diff --git a/WebCms/Controllers/EnforceTrueAttribute.cs b/WebCms/Controllers/EnforceTrueAttribute.cs index 3a03418..402bbe9 100644 --- a/WebCms/Controllers/EnforceTrueAttribute.cs +++ b/WebCms/Controllers/EnforceTrueAttribute.cs @@ -5,7 +5,7 @@ using System.Web.Mvc; namespace LeafWeb.WebCms.Controllers { - // http://stackoverflow.com/a/9036075/99492 + // TODO http://stackoverflow.com/a/9036075/99492 public class EnforceTrueAttribute : ValidationAttribute, IClientValidatable { public override bool IsValid(object value) diff --git a/WebCms/EventHandlers/MemberRegistrationEventHandler.cs b/WebCms/EventHandlers/MemberRegistrationEventHandler.cs new file mode 100644 index 0000000..8ffddfe --- /dev/null +++ b/WebCms/EventHandlers/MemberRegistrationEventHandler.cs @@ -0,0 +1,29 @@ +using Hangfire; +using LeafWeb.WebCms.Services; +using Umbraco.Core; +using Umbraco.Core.Events; +using Umbraco.Core.Models; +using Umbraco.Core.Services; + +namespace LeafWeb.WebCms.EventHandlers +{ + // https://our.umbraco.com/forum/umbraco-7/using-umbraco-7/64185-Assign-new-members-to-member-group-upon-registration#comment-254768 + public class MemberRegistrationEventHandler : ApplicationEventHandler + { + protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) + { + base.ApplicationStarted(umbracoApplication, applicationContext); + MemberService.Created += MemberService_Created; + } + + private void MemberService_Created(IMemberService sender, NewEventArgs e) + { + sender.AssignRole(e.Entity.Username, "Unverified"); + sender.Save(e.Entity); + + // Send Email + BackgroundJob.Enqueue( + email => email.SendVerifyMemberEmail(e.Entity)); + } + } +} \ No newline at end of file diff --git a/WebCms/Services/EmailNotificationService.cs b/WebCms/Services/EmailNotificationService.cs index 7668cb2..a91b571 100644 --- a/WebCms/Services/EmailNotificationService.cs +++ b/WebCms/Services/EmailNotificationService.cs @@ -1,7 +1,5 @@ using System; using System.Configuration; -using System.IO; -using System.Linq; using System.Net; using System.Net.Mail; using log4net; @@ -9,6 +7,7 @@ using LeafWeb.Core.DAL; using LeafWeb.Core.Entities; using LeafWeb.Core.Utility; using LeafWeb.WebCms.Models; +using Umbraco.Core.Models; namespace LeafWeb.WebCms.Services { @@ -198,6 +197,11 @@ namespace LeafWeb.WebCms.Services SendMessage(message); } + public void SendVerifyMemberEmail(IMember member) + { + // TODO: write verify email to user + } + private string FormatWarningMessage(LeafInput leafInput) { if (leafInput.OutputWarningMessage != null) diff --git a/WebCms/Views/LeafInput/Create.cshtml b/WebCms/Views/LeafInput/Create.cshtml index 22681d7..1258f3d 100644 --- a/WebCms/Views/LeafInput/Create.cshtml +++ b/WebCms/Views/LeafInput/Create.cshtml @@ -1,5 +1,6 @@ @using ClientDependency.Core.Mvc @using LeafWeb.WebCms.Controllers +@using Umbraco.Web @model LeafInputCreate @{ Html.RequiresCss("~/backload/blueimp/bootstrap/BasicPlusUI/css"); @@ -9,15 +10,17 @@ Html.RequiresJs("~/scripts/jquery.validate.unobtrusive.bootstrap.min.js", 2); Html.RequiresJs("~/scripts/jquery.validate.custom.js", 2); Html.RequiresJs("~/scripts/LeafInputCreate.js", 3); + + var user = Membership.GetUser(); }
-
+
@Html.Partial("_ValidationSummary")
- +

Files

@@ -60,18 +63,30 @@
- @using (Html.BeginUmbracoForm("Submit", null, new {id = "create"})) + @using (Html.BeginUmbracoForm("Submit", null, new { id = "create" })) { @Html.EditorFor(m => m.PhotosynthesisType) @Html.EditorFor(m => m.Identifier) @Html.EditorFor(m => m.SiteId) - @Html.EditorFor(m => m.Name) - @Html.EditorFor(m => m.Email) - @Html.EditorFor(m => m.EmailConfirm) + if (user == null) + { + @Html.EditorFor(m => m.Name) + @Html.EditorFor(m => m.Email) + @Html.EditorFor(m => m.EmailConfirm) + } + else + { + @Html.HiddenFor(m => m.Name) + @Html.HiddenFor(m => m.Email) + @Html.HiddenFor(m => m.EmailConfirm) + } @Html.EditorFor(m => m.TermsOfService) - + } - +
+ +
+
diff --git a/WebCms/Views/MacroPartials/Membership/Login.cshtml b/WebCms/Views/MacroPartials/Membership/Login.cshtml index 5b9abcd..a54044a 100644 --- a/WebCms/Views/MacroPartials/Membership/Login.cshtml +++ b/WebCms/Views/MacroPartials/Membership/Login.cshtml @@ -1,34 +1,27 @@ @inherits Umbraco.Web.Macros.PartialViewMacroPage @using System.Web.Mvc.Html -@using ClientDependency.Core.Mvc @using Umbraco.Web @using Umbraco.Web.Models @using Umbraco.Web.Controllers @{ var loginModel = new LoginModel { RedirectUrl = "/leaf-data/manage-queue/" }; - - Html.EnableClientValidation(); - Html.EnableUnobtrusiveJavaScript(); - Html.RequiresJs("~/scripts/jquery.validate.min.js"); - Html.RequiresJs("~/scripts/jquery.validate.unobtrusive.min.js"); - Html.RequiresJs("~/scripts/jquery.validate.unobtrusive.bootstrap.min.js"); } -
-
-
+
+
+
@using (Html.BeginUmbracoForm("HandleLogin")) {
@Html.ValidationSummary("loginModel", true)
@Html.LabelFor(m => loginModel.Username) - @Html.TextBoxFor(m => loginModel.Username) + @Html.TextBoxFor(m => loginModel.Username, new {@class = "form-control" }) @Html.ValidationMessageFor(m => loginModel.Username)
@Html.LabelFor(m => loginModel.Password) - @Html.PasswordFor(m => loginModel.Password) + @Html.PasswordFor(m => loginModel.Password, new {@class = "form-control" }) @Html.ValidationMessageFor(m => loginModel.Password)
diff --git a/WebCms/Views/MacroPartials/Membership/Register.cshtml b/WebCms/Views/MacroPartials/Membership/Register.cshtml new file mode 100644 index 0000000..e3300e8 --- /dev/null +++ b/WebCms/Views/MacroPartials/Membership/Register.cshtml @@ -0,0 +1,77 @@ +@inherits Umbraco.Web.Macros.PartialViewMacroPage +@using ClientDependency.Core.Mvc +@using Umbraco.Web.Controllers + + +@{ + var membershipHelper = new Umbraco.Web.Security.MembershipHelper(UmbracoContext.Current); + var registerModel = membershipHelper.CreateRegistrationModel(); + + var success = TempData["FormSuccess"] != null; + + Html.EnableClientValidation(); + Html.RequiresJs("~/scripts/jquery.validate.min.js", 2); + Html.RequiresJs("~/scripts/jquery.validate.unobtrusive.min.js", 2); + + Html.RequiresJs("~/scripts/Register.js"); +} + +
+
+
+@if (success) +{ +

Registration succeeded.

+} +else +{ + using (Html.BeginUmbracoForm( + "HandleRegisterMember", + null, + new {id="register-member"})) + { +
+ @Html.ValidationSummary("registerModel", true) + + @Html.LabelFor(m => registerModel.Name) + @Html.TextBoxFor(m => registerModel.Name, new { @class = "form-control" }) + @Html.ValidationMessageFor(m => registerModel.Name) +
+
+ @Html.LabelFor(m => registerModel.Email) + @Html.TextBoxFor(m => registerModel.Email, new { @class = "form-control" }) + @Html.ValidationMessageFor(m => registerModel.Email) +
+
+ @Html.LabelFor(m => registerModel.Password) + @Html.PasswordFor(m => registerModel.Password, new { @class = "form-control" }) + @Html.ValidationMessageFor(m => registerModel.Password) +
+
+ @Html.Label("VerifyPassword") + @Html.Password("VerifyPassword", null, new { @class = "form-control" }) + @Html.ValidationMessage("VerifyPassword") +
+ + if (registerModel.MemberProperties != null) + { + for (var i = 0; i < registerModel.MemberProperties.Count; i++) + { +
+ @Html.LabelFor(m => registerModel.MemberProperties[i].Value, registerModel.MemberProperties[i].Name) + @Html.EditorFor(m => registerModel.MemberProperties[i].Value, new { @class = "form-control" }) + @Html.HiddenFor(m => registerModel.MemberProperties[i].Alias) +
+ } + } + + @Html.HiddenFor(m => registerModel.MemberTypeAlias) + @Html.HiddenFor(m => registerModel.RedirectUrl) + @Html.HiddenFor(m => registerModel.UsernameIsEmail) + + + } +} +
+
+
\ No newline at end of file diff --git a/WebCms/Views/Master.cshtml b/WebCms/Views/Master.cshtml index c82be45..5513255 100644 --- a/WebCms/Views/Master.cshtml +++ b/WebCms/Views/Master.cshtml @@ -11,7 +11,7 @@ } else if (TempData.ContainsKey("LogoutSuccess") && (bool)TempData["LogoutSuccess"]) { - TempData["StatusMessage"] = "Logout sucessful"; + TempData["StatusMessage"] = "Logout successful"; TempData["StatusMessage-Type"] = "alert-success"; } Html.RequiresCss("~/Content/bootstrap_leafweb.css"); diff --git a/WebCms/Views/Partials/LoginStatus.cshtml b/WebCms/Views/Partials/LoginStatus.cshtml index 52d223e..b95d01f 100644 --- a/WebCms/Views/Partials/LoginStatus.cshtml +++ b/WebCms/Views/Partials/LoginStatus.cshtml @@ -1,16 +1,10 @@ @inherits UmbracoTemplatePage @using System.Web.Mvc.Html -@using ClientDependency.Core.Mvc @using Umbraco.Web @using Umbraco.Web.Models @using Umbraco.Web.Controllers @{ var loginStatusModel = Members.GetCurrentLoginStatus(); - - Html.RequiresJs("~/scripts/jquery.validate.min.js"); - Html.RequiresJs("~/scripts/jquery.validate.unobtrusive.min.js"); - Html.RequiresJs("~/scripts/jquery.validate.unobtrusive.bootstrap.min.js"); - var logoutModel = new PostRedirectModel { RedirectUrl = "/" }; }
diff --git a/WebCms/Views/Web.config b/WebCms/Views/Web.config index 867371e..9ba3fb8 100644 --- a/WebCms/Views/Web.config +++ b/WebCms/Views/Web.config @@ -1,63 +1,71 @@  - -
-
- - - - + +
+
+ + - - - - - - - - - - - - + - - - - + + + + + + + + + + + + + + - - - - - - - - - - + + + + + + + + + - - - - - - - - - - - - - - \ No newline at end of file + + + + + + + + + + + + + + \ No newline at end of file diff --git a/WebCms/WebCms.csproj b/WebCms/WebCms.csproj index dc192ad..ef5bb59 100644 --- a/WebCms/WebCms.csproj +++ b/WebCms/WebCms.csproj @@ -37,7 +37,7 @@ bin\ DEBUG;TRACE prompt - 4 + 2 pdbonly @@ -895,6 +895,7 @@ + @@ -1060,6 +1061,7 @@ + Web.config @@ -1095,6 +1097,7 @@ + @@ -1122,6 +1125,7 @@ + diff --git a/WebCms/macroScripts/web.config b/WebCms/macroScripts/web.config new file mode 100644 index 0000000..c98c893 --- /dev/null +++ b/WebCms/macroScripts/web.config @@ -0,0 +1,56 @@ + + + + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/WebCms/scripts/Register.js b/WebCms/scripts/Register.js new file mode 100644 index 0000000..2681a82 --- /dev/null +++ b/WebCms/scripts/Register.js @@ -0,0 +1,23 @@ +$(function () { + $("#register-member").validate(); + $('#VerifyPassword') + .rules("add", + { + required: true, + equalTo: "#registerModel_Password", + messages: { + required: "Verify Password is required", + equalTo: jQuery.validator.format("Passwords do not match") + } + } + ); + $('#registerModel_Name') + .rules("add", + { + required: true, + messages: { + required: "Name is required" + } + } + ); +}); \ No newline at end of file diff --git a/WebCms/scripts/site.js b/WebCms/scripts/site.js index f998acd..d0556b7 100644 --- a/WebCms/scripts/site.js +++ b/WebCms/scripts/site.js @@ -26,7 +26,7 @@ }); return false; }); - + /* // Making elements equal height var equalheight = function(container){ @@ -109,7 +109,7 @@ $(this).toggleClass('selected'); } } - }); + }); */ $(".read-more") .click(function () { @@ -120,6 +120,20 @@ else $(this).text("Show Less"); return false; - }); + }); + + // https://stackoverflow.com/a/58215644/99492 + $.validator.setDefaults({ + errorClass: "", + validClass: "", + highlight: function (element, errorClass, validClass) { + $(element).addClass("is-invalid").removeClass("is-valid"); + $(element.form).find("[data-valmsg-for=" + element.id + "]").addClass("invalid-feedback"); + }, + unhighlight: function (element, errorClass, validClass) { + $(element).addClass("is-valid").removeClass("is-invalid"); + $(element.form).find("[data-valmsg-for=" + element.id + "]").removeClass("invalid-feedback"); + } + }); })(jQuery); \ No newline at end of file