From 9b06522c668ff8d2c27367529553eab6bded2021 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 18 May 2017 21:25:20 -0400 Subject: [PATCH] feedback --- Project-Unite/ACL.cs | 9 ++ Project-Unite/Controllers/HomeController.cs | 46 ++++++++++ Project-Unite/Models/AdminViewModels.cs | 1 + Project-Unite/Models/SendFeedbackViewModel.cs | 56 ++++++++++++ Project-Unite/Project-Unite.csproj | 2 + Project-Unite/Views/Home/SendFeedback.cshtml | 42 +++++++++ .../Views/Shared/_LoginPartial.cshtml | 87 ++++++++++--------- 7 files changed, 200 insertions(+), 43 deletions(-) create mode 100644 Project-Unite/Models/SendFeedbackViewModel.cs create mode 100644 Project-Unite/Views/Home/SendFeedback.cshtml diff --git a/Project-Unite/ACL.cs b/Project-Unite/ACL.cs index 74ac07e..d589fc3 100644 --- a/Project-Unite/ACL.cs +++ b/Project-Unite/ACL.cs @@ -44,6 +44,15 @@ public static IHtmlString NewestUser(this HtmlHelper hpr) return hpr.Raw(" Our newest user, " + user.DisplayName + ""); } + internal static string MarkdownRaw(string md) + { + if (md == null) + return ""; + md = ResolveUserLinksInMarkdown(md); + return CommonMark.CommonMarkConverter.Convert(md); + + } + public static IHtmlString GetLatestUnread(this HtmlHelper hpr, string userName) { var db = new ApplicationDbContext(); diff --git a/Project-Unite/Controllers/HomeController.cs b/Project-Unite/Controllers/HomeController.cs index 53fe20d..20141ce 100644 --- a/Project-Unite/Controllers/HomeController.cs +++ b/Project-Unite/Controllers/HomeController.cs @@ -4,12 +4,58 @@ using System.Net; using System.Web; using System.Web.Mvc; +using Microsoft.AspNet.Identity; using Project_Unite.Models; namespace Project_Unite.Controllers { public class HomeController : Controller { + public ActionResult SendFeedback() + { + var sfm = new SendFeedbackViewModel(); + if(Request.IsAuthenticated) + { + var db = new ApplicationDbContext(); + var user = db.Users.FirstOrDefault(x => x.UserName == User.Identity.Name); + sfm.Name = (string.IsNullOrWhiteSpace(user.FullName)) ? user.DisplayName : user.FullName; + sfm.Email = user.Email; + } + return View(sfm); + } + + [HttpPost] + [ValidateAntiForgeryToken] + public ActionResult SendFeedback(SendFeedbackViewModel model) + { + if (!ModelState.IsValid) + return View(model); + + var db = new ApplicationDbContext(); + var siteconfig = db.Configs.FirstOrDefault(); + + var mailsender = new EmailService(); + var message = new IdentityMessage + { + Destination = siteconfig.FeedbackEmail, + Subject = "[Feedback] " + model.Name, + Body = $@"

Project: Unite Feedback

+ +
+
From:
+
{model.Name} [{model.Email}]
+
Type:
+
{model.FeedbackType}
+
+ +
+ +{ACL.MarkdownRaw(model.Body)}" + }; + mailsender.SendAsync(message); + return RedirectToAction("Index"); + } + public ActionResult AccessDenied() { return View(); diff --git a/Project-Unite/Models/AdminViewModels.cs b/Project-Unite/Models/AdminViewModels.cs index a03775e..8a6425e 100644 --- a/Project-Unite/Models/AdminViewModels.cs +++ b/Project-Unite/Models/AdminViewModels.cs @@ -75,6 +75,7 @@ public enum AuditLogLevel public class Configuration { public string Id { get; set; } + public string FeedbackEmail { get; set; } public string SiteName { get; set; } public string ReturnEmail { get; set; } public string UniteBotToken { get; set; } diff --git a/Project-Unite/Models/SendFeedbackViewModel.cs b/Project-Unite/Models/SendFeedbackViewModel.cs new file mode 100644 index 0000000..995c599 --- /dev/null +++ b/Project-Unite/Models/SendFeedbackViewModel.cs @@ -0,0 +1,56 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Web; +using System.Web.Mvc; + +namespace Project_Unite.Models +{ + public class SendFeedbackViewModel + { + [Required(AllowEmptyStrings = false, ErrorMessage ="You must provide a name so we can address you properly.")] + public string Name { get; set; } + + [DataType(DataType.EmailAddress)] + [Required(AllowEmptyStrings = false, ErrorMessage = "You must provide a valid email address so we can reply to your feedback.")] + public string Email { get; set; } + + [Required(AllowEmptyStrings = false, ErrorMessage = "Please provide a subject.")] + [MinLength(5, ErrorMessage ="Your subject must be at least 5 characters long.")] + [MaxLength(35, ErrorMessage = "Your subject must be less than 35 characters long.")] + public string Subject { get; set; } + + [Required(AllowEmptyStrings =false, ErrorMessage ="Please enter a body for your feedback email.")] + [AllowHtml] + public string Body { get; set; } + + public string FeedbackType { get; set; } + + public List FeedbackTypes + { + get + { + string[] types = new string[] + { + "Feature Request - Website", + "Feature Request - ShiftOS Client", + "Feature Request - API", + "Security and Privacy", + "Discord", + "YouTube Channel", + "Ban Appeals", + "Other" + }; + List items = new List(); + foreach (var type in types) + items.Add(new SelectListItem + { + Value = type, + Text = type + }); + return items; + } + } + } +} \ No newline at end of file diff --git a/Project-Unite/Project-Unite.csproj b/Project-Unite/Project-Unite.csproj index dd1e06a..6fcf989 100644 --- a/Project-Unite/Project-Unite.csproj +++ b/Project-Unite/Project-Unite.csproj @@ -820,6 +820,7 @@ + @@ -963,6 +964,7 @@ + diff --git a/Project-Unite/Views/Home/SendFeedback.cshtml b/Project-Unite/Views/Home/SendFeedback.cshtml new file mode 100644 index 0000000..9d26f29 --- /dev/null +++ b/Project-Unite/Views/Home/SendFeedback.cshtml @@ -0,0 +1,42 @@ +@model Project_Unite.Models.SendFeedbackViewModel +@{ + ViewBag.Title = "Send feedback"; +} + +

Send feedback

+ +

Hey there, Shifter! Michael here. So, you want to get in touch with the ShiftOS team, do ya? Well, just fill out this form!

+ +@using (Html.BeginForm()) +{ + @Html.AntiForgeryToken() + @Html.ValidationSummary() + +
+
Your name:
+
Just in case I need it, can you please enter your name here? @Html.TextBoxFor(x=>x.Name, new{@class="form-control"})
+ +
Your email:
+
May you please enter your email address so I can reply to you if needed? @Html.TextBoxFor(x => x.Email, new { type="email", @class = "form-control" })
+ +
Feedback type:
+
@Html.DropDownListFor(x => x.Name, Model.FeedbackTypes, new { @class = "form-control" })
+ +
Subject:
+
@Html.TextBoxFor(x => x.Subject, new { @class = "form-control" })
+ +
Body:
+
@Html.TextAreaFor(x => x.Body, new { @class = "form-control" })
+ +
+ + +} + +

Bogus email addresses

+ +

Please note that if you enter a bogus email address, we will completely ignore your feedback. This is because I want to be talking with real people, not spammers. If I can't reach you, I just won't listen to you.

+ +

This is NOT for general communication!

+ +

Please only use this form for feedback/support for ShiftOS. If you want to get in contact with me for other reasons, join our Discord server or email me directly at this address.

\ No newline at end of file diff --git a/Project-Unite/Views/Shared/_LoginPartial.cshtml b/Project-Unite/Views/Shared/_LoginPartial.cshtml index a8fa210..0d1c22b 100644 --- a/Project-Unite/Views/Shared/_LoginPartial.cshtml +++ b/Project-Unite/Views/Shared/_LoginPartial.cshtml @@ -1,51 +1,52 @@ @using Microsoft.AspNet.Identity - -@if (Request.IsAuthenticated) -{ - using (Html.BeginForm("LogOff", "Account", FormMethod.Post, new { id = "logoutForm", @class = "navbar-right" })) + \ No newline at end of file