From b674590b8c6d9353f5d71a309d0f576eddb2ed9b Mon Sep 17 00:00:00 2001 From: Uncled1023 Date: Wed, 20 Jun 2018 21:36:05 -0700 Subject: [PATCH] Fixed formatting of blog/vault editors. Fixed paste output not working correctly in


---
 Teknik/Areas/Blog/Views/Blog/EditPost.cshtml  | 16 +++++---
 Teknik/Areas/Blog/Views/Blog/NewPost.cshtml   | 16 +++++---
 .../Paste/Controllers/PasteController.cs      | 21 ++++------
 Teknik/Areas/Paste/Views/Paste/Full.cshtml    |  2 +-
 .../Paste/Views/Paste/PasswordNeeded.cshtml   | 12 +++++-
 Teknik/Areas/Paste/Views/Paste/Simple.cshtml  |  2 +-
 .../Vault/Views/Vault/ModifyVault.cshtml      | 10 +++--
 .../Areas/Vault/Views/Vault/PasteItem.cshtml  |  2 +-
 Teknik/Routes.cs                              |  8 ++--
 Utilities/HtmlHelper.cs                       | 40 +++++++++++++++++++
 Utilities/MarkdownHelper.cs                   | 12 ------
 11 files changed, 92 insertions(+), 49 deletions(-)
 create mode 100644 Utilities/HtmlHelper.cs

diff --git a/Teknik/Areas/Blog/Views/Blog/EditPost.cshtml b/Teknik/Areas/Blog/Views/Blog/EditPost.cshtml
index d3bf5f0..9b0908b 100644
--- a/Teknik/Areas/Blog/Views/Blog/EditPost.cshtml
+++ b/Teknik/Areas/Blog/Views/Blog/EditPost.cshtml
@@ -25,21 +25,23 @@
     
         
         
-
+
-
+
-
- +
+ +
+

-
+
Article
@@ -48,7 +50,9 @@
-
+
+
+
Preview
diff --git a/Teknik/Areas/Blog/Views/Blog/NewPost.cshtml b/Teknik/Areas/Blog/Views/Blog/NewPost.cshtml index 320fbac..2ca7f6d 100644 --- a/Teknik/Areas/Blog/Views/Blog/NewPost.cshtml +++ b/Teknik/Areas/Blog/Views/Blog/NewPost.cshtml @@ -25,21 +25,23 @@
-
+
-
+
-
- +
+ +
+

-
+
Article
@@ -48,7 +50,9 @@
-
+
+
+
Preview
diff --git a/Teknik/Areas/Paste/Controllers/PasteController.cs b/Teknik/Areas/Paste/Controllers/PasteController.cs index 578e78c..812f30b 100644 --- a/Teknik/Areas/Paste/Controllers/PasteController.cs +++ b/Teknik/Areas/Paste/Controllers/PasteController.cs @@ -98,6 +98,13 @@ namespace Teknik.Areas.Paste.Controllers PasswordViewModel passModel = new PasswordViewModel(); passModel.Url = url; passModel.Type = type; + + if (!string.IsNullOrEmpty(password) && hash != paste.HashedPassword) + { + passModel.Error = true; + passModel.ErrorMessage = "Invalid Password"; + } + // Redirect them to the password request page return View("~/Areas/Paste/Views/Paste/PasswordNeeded.cshtml", passModel); } @@ -110,18 +117,6 @@ namespace Teknik.Areas.Paste.Controllers model.Content = Encoding.Unicode.GetString(data); } - if (type.ToLower() == "full" || type.ToLower() == "simple") - { - // Transform content into HTML - //if (!Highlighter.Lexers.ToList().Exists(l => l.Aliases.Contains(model.Syntax))) - //{ - // model.Syntax = "text"; - //} - //Highlighter highlighter = new Highlighter(); - // Add a space in front of the content due to bug with pygment (No idea why yet) - model.Content = model.Content;//highlighter.HighlightToHtml(" " + model.Content, model.Syntax, _config.PasteConfig.SyntaxVisualStyle, generateInlineStyles: true, fragment: true); - } - switch (type.ToLower()) { case "full": @@ -134,7 +129,7 @@ namespace Teknik.Areas.Paste.Controllers //Create File var cd = new System.Net.Mime.ContentDisposition { - FileName = url, + FileName = url + ".txt", Inline = true }; diff --git a/Teknik/Areas/Paste/Views/Paste/Full.cshtml b/Teknik/Areas/Paste/Views/Paste/Full.cshtml index ad12b29..7f8529f 100644 --- a/Teknik/Areas/Paste/Views/Paste/Full.cshtml +++ b/Teknik/Areas/Paste/Views/Paste/Full.cshtml @@ -68,7 +68,7 @@
-
@Html.Raw(Model.Content)
+
@Model.Content
diff --git a/Teknik/Areas/Paste/Views/Paste/PasswordNeeded.cshtml b/Teknik/Areas/Paste/Views/Paste/PasswordNeeded.cshtml index 01fdb87..8ac4206 100644 --- a/Teknik/Areas/Paste/Views/Paste/PasswordNeeded.cshtml +++ b/Teknik/Areas/Paste/Views/Paste/PasswordNeeded.cshtml @@ -1,10 +1,20 @@ @model Teknik.Areas.Paste.ViewModels.PasswordViewModel
+ @if (Model.Error) + { +
+
+
+ @Model.ErrorMessage +
+
+
+ }
-

This paste is password protected.

+

This paste is password protected

diff --git a/Teknik/Areas/Paste/Views/Paste/Simple.cshtml b/Teknik/Areas/Paste/Views/Paste/Simple.cshtml index fd1a1ab..3d6b5a8 100644 --- a/Teknik/Areas/Paste/Views/Paste/Simple.cshtml +++ b/Teknik/Areas/Paste/Views/Paste/Simple.cshtml @@ -48,7 +48,7 @@ var highlightSrc = '@Url.FullURL("~/js/highlight.min.js")'; -
@Html.Raw(Model.Content)
+
@Model.Content
diff --git a/Teknik/Areas/Vault/Views/Vault/ModifyVault.cshtml b/Teknik/Areas/Vault/Views/Vault/ModifyVault.cshtml index 701df3a..dcdf199 100644 --- a/Teknik/Areas/Vault/Views/Vault/ModifyVault.cshtml +++ b/Teknik/Areas/Vault/Views/Vault/ModifyVault.cshtml @@ -127,22 +127,24 @@
-
+
-
+
Description
- +
-
+
+
+
Preview
diff --git a/Teknik/Areas/Vault/Views/Vault/PasteItem.cshtml b/Teknik/Areas/Vault/Views/Vault/PasteItem.cshtml index 4fca251..72894cc 100644 --- a/Teknik/Areas/Vault/Views/Vault/PasteItem.cshtml +++ b/Teknik/Areas/Vault/Views/Vault/PasteItem.cshtml @@ -54,7 +54,7 @@ } else { -
@Html.Raw(Model.Paste.Content)
+
@Model.Paste.Content
}
diff --git a/Teknik/Routes.cs b/Teknik/Routes.cs index a12a075..c2bf71c 100644 --- a/Teknik/Routes.cs +++ b/Teknik/Routes.cs @@ -400,21 +400,21 @@ namespace Teknik name: "Paste.Simple", domains: new List() { config.Host }, subDomains: new List() { "paste", "p" }, - template: "Simple/{url}", + template: "Simple/{url}/{password?}", defaults: new { area = "Paste", controller = "Paste", action = "ViewPaste", type = "Simple" } ); routes.MapSubdomainRoute( name: "Paste.Raw", domains: new List() { config.Host }, subDomains: new List() { "paste", "p" }, - template: "Raw/{url}", + template: "Raw/{url}/{password?}", defaults: new { area = "Paste", controller = "Paste", action = "ViewPaste", type = "Raw" } ); routes.MapSubdomainRoute( name: "Paste.Download", domains: new List() { config.Host }, subDomains: new List() { "paste", "p" }, - template: "Download/{url}", + template: "Download/{url}/{password?}", defaults: new { area = "Paste", controller = "Paste", action = "ViewPaste", type = "Download" } ); routes.MapSubdomainRoute( @@ -428,7 +428,7 @@ namespace Teknik name: "Paste.View", domains: new List() { config.Host }, subDomains: new List() { "paste", "p" }, - template: "{url}", + template: "{url}/{password?}", defaults: new { area = "Paste", controller = "Paste", action = "ViewPaste", type = "Full" } ); } diff --git a/Utilities/HtmlHelper.cs b/Utilities/HtmlHelper.cs new file mode 100644 index 0000000..fd2ba69 --- /dev/null +++ b/Utilities/HtmlHelper.cs @@ -0,0 +1,40 @@ +using Ganss.XSS; +using Microsoft.AspNetCore.Html; +using Microsoft.AspNetCore.Mvc.Rendering; +using System; +using System.Collections.Generic; +using System.Text; + +namespace Teknik.Utilities +{ + public static class HtmlHelper + { + /// + /// Transforms a string of Markdown into HTML. + /// + /// HtmlHelper - Not used, but required to make this an extension method. + /// The Markdown that should be transformed. + /// The HTML representation of the supplied Markdown. + public static HtmlString Markdown(this IHtmlHelper helper, string text) + { + // Just call the other one, to avoid having two copies (we don't use the HtmlHelper). + return MarkdownHelper.Markdown(text); + } + + /// + /// Sanitizes a string from HTML. + /// + /// HtmlHelper - Not used, but required to make this an extension method. + /// The Markdown that should be transformed. + /// The HTML representation of the supplied Markdown. + public static HtmlString Sanitize(this IHtmlHelper helper, string text) + { + // Sanitize Text + var sanitizer = new HtmlSanitizer(); + var sanText = sanitizer.Sanitize(text); + + // Wrap the html in an MvcHtmlString otherwise it'll be HtmlEncoded and displayed to the user as HTML :( + return new HtmlString(sanText); + } + } +} diff --git a/Utilities/MarkdownHelper.cs b/Utilities/MarkdownHelper.cs index 3c475d6..0ac076c 100644 --- a/Utilities/MarkdownHelper.cs +++ b/Utilities/MarkdownHelper.cs @@ -29,18 +29,6 @@ namespace Teknik.Utilities return new HtmlString(html); } - /// - /// Transforms a string of Markdown into HTML. - /// - /// HtmlHelper - Not used, but required to make this an extension method. - /// The Markdown that should be transformed. - /// The HTML representation of the supplied Markdown. - public static HtmlString Markdown(this IHtmlHelper helper, string text) - { - // Just call the other one, to avoid having two copies (we don't use the HtmlHelper). - return Markdown(text); - } - public static MarkdownPipeline BuildPipeline() { return new MarkdownPipelineBuilder() // Use similar to advanced extension without auto-identifier