Add membership verification
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
using System.Web.Mvc;
|
||||
using Umbraco.Core;
|
||||
|
||||
namespace LeafWeb.WebCms.Controllers
|
||||
{
|
||||
public class MembershipController : BaseController
|
||||
{
|
||||
public ActionResult Verify(string email, string token)
|
||||
{
|
||||
var redirectUrl = "/";
|
||||
|
||||
var memberService = ApplicationContext.Current.Services.MemberService;
|
||||
var member = memberService.GetByEmail(email);
|
||||
if (member == null)
|
||||
{
|
||||
TempData["StatusMessage"] = $"User with email {email} not found.";
|
||||
TempData["StatusMessage-Type"] = "alert-danger";
|
||||
}
|
||||
else if (member.IsApproved)
|
||||
{
|
||||
TempData["StatusMessage"] = "You've already been verified, " + member.Name;
|
||||
TempData["StatusMessage-Type"] = "alert-info";
|
||||
}
|
||||
else
|
||||
{
|
||||
var storedToken = member.GetValue("VerificationToken") as string;
|
||||
|
||||
if (string.IsNullOrEmpty(storedToken))
|
||||
{
|
||||
TempData["StatusMessage"] = $"No verification token exists for this user.";
|
||||
TempData["StatusMessage-Type"] = "alert-danger";
|
||||
}
|
||||
else if (storedToken != token)
|
||||
{
|
||||
TempData["StatusMessage"] = $"Bad token.";
|
||||
TempData["StatusMessage-Type"] = "alert-danger";
|
||||
}
|
||||
else
|
||||
{
|
||||
// member is now verified
|
||||
member.IsApproved = true;
|
||||
|
||||
// remove the verification
|
||||
member.SetValue("VerificationToken", string.Empty);
|
||||
memberService.Save(member);
|
||||
|
||||
TempData["StatusMessage"] = "You have been verified, " + member.Name;
|
||||
TempData["StatusMessage-Type"] = "alert-success";
|
||||
|
||||
// TODO: rewrite url to their own page
|
||||
}
|
||||
}
|
||||
|
||||
return Redirect(redirectUrl);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@ namespace LeafWeb.WebCms.EventHandlers
|
||||
{
|
||||
protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
|
||||
{
|
||||
base.ApplicationStarted(umbracoApplication, applicationContext);
|
||||
//base.ApplicationStarted(umbracoApplication, applicationContext);
|
||||
MemberService.Created += MemberService_Created;
|
||||
MemberService.Saving += MemberService_OnSaving;
|
||||
}
|
||||
@@ -32,7 +32,7 @@ namespace LeafWeb.WebCms.EventHandlers
|
||||
//Member wasn't approved before save but is now
|
||||
if (!alreadyApproved)
|
||||
{
|
||||
//Code to send email goes here
|
||||
//todo Code to send email goes here
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -203,8 +203,7 @@ namespace LeafWeb.WebCms.Services
|
||||
|
||||
public void SendVerifyMemberEmail(string memberEmail)
|
||||
{
|
||||
var servicesMemberService = ApplicationContext.Current.Services.MemberService;
|
||||
var member = servicesMemberService.GetByEmail(memberEmail);
|
||||
var member = ApplicationContext.Current.Services.MemberService.GetByEmail(memberEmail);
|
||||
var verifyEmailURl = _urlService.GetVerifyEmailURl(member);
|
||||
var body = "Please verify your email address with this link " + verifyEmailURl;
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using System.Configuration;
|
||||
using System.Web;
|
||||
using LeafWeb.Core.Entities;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Web.PublishedCache;
|
||||
|
||||
namespace LeafWeb.WebCms.Services
|
||||
{
|
||||
@@ -15,7 +15,11 @@ namespace LeafWeb.WebCms.Services
|
||||
_downloadUrl =
|
||||
ConfigurationManager.AppSettings["LeafWebUrl"]
|
||||
+ ConfigurationManager.AppSettings["ResultsDownloadPath"];
|
||||
}
|
||||
|
||||
_verifyEmailUrl =
|
||||
ConfigurationManager.AppSettings["LeafWebUrl"]
|
||||
+ ConfigurationManager.AppSettings["MemberVerifyPath"];
|
||||
}
|
||||
|
||||
public string GetDownloadUrl(LeafInput leafInput)
|
||||
{
|
||||
@@ -26,8 +30,7 @@ namespace LeafWeb.WebCms.Services
|
||||
{
|
||||
var memberEmail = member.Email;
|
||||
var token = member.GetValue("VerificationToken") as string;
|
||||
var verifyEmailToken = _downloadUrl + "/verify?email={0}&token={1}";
|
||||
return string.Format(verifyEmailToken, memberEmail, token);
|
||||
return string.Format(_verifyEmailUrl, HttpUtility.UrlEncode(memberEmail), token);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,15 @@
|
||||
Html.RequiresJs("~/scripts/jquery.validate.unobtrusive.min.js", 2);
|
||||
|
||||
Html.RequiresJs("~/scripts/Register.js");
|
||||
|
||||
var user = Membership.GetUser();
|
||||
if (user != null)
|
||||
{
|
||||
TempData["StatusMessage"] = "You are already logged in, " + user.UserName;
|
||||
TempData["StatusMessage-Type"] = "alert-danger";
|
||||
|
||||
// todo: redirect
|
||||
}
|
||||
}
|
||||
|
||||
<div class="container mt-5">
|
||||
|
||||
@@ -60,7 +60,7 @@
|
||||
@RenderSection("Styles", false)
|
||||
</head>
|
||||
|
||||
<body @{if (CompileFlag.IsDebug()) {<text>class="debug"</text>}}>
|
||||
<body class="@{if (CompileFlag.IsDebug()) {<text>debug</text>}}">
|
||||
<header>
|
||||
<div class="container-lg">
|
||||
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
|
||||
@@ -83,15 +83,16 @@
|
||||
|
||||
</div>
|
||||
</header>
|
||||
@Html.Partial("_StatusMessage")
|
||||
<main role="main">
|
||||
@Html.Partial("_StatusMessage")
|
||||
|
||||
@RenderBody()
|
||||
|
||||
<footer class="field dark">
|
||||
@RenderBody()
|
||||
</main>
|
||||
<footer class="mt-auto py-3 dark">
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
|
||||
@{ // ReSharper disable once Mvc.PartialViewNotResolved
|
||||
|
||||
@{ // ReSharper disable once Mvc.PartialViewNotResolved
|
||||
Html.RenderPartial("BottomNavigation"); }
|
||||
|
||||
</div>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
@model int
|
||||
@using LeafWeb.WebCms.Controllers
|
||||
@model int
|
||||
@{
|
||||
var url = UmbracoContext.Current.UrlProvider.GetUrl(1111);
|
||||
var url = UmbracoContext.Current.UrlProvider.GetUrl(LeafWebPageIds.Details);
|
||||
}
|
||||
<a href="@url?id=@Model">
|
||||
<span class="fa fa-edit"></span> Details
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
$(function () {
|
||||
initFileUpload("@Session.SessionID");
|
||||
$('input#SiteId').autocomplete({
|
||||
serviceUrl: '/umbraco/surface/FluxnetSite/Autocomplete'
|
||||
serviceUrl: '/FluxnetSiteAutocomplete'
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
+19
-3
@@ -73,9 +73,10 @@
|
||||
<add key="SmtpPort" value="25" />
|
||||
<add key="SmtpUserName" value="" />
|
||||
<add key="SmtpPassword" value="" />
|
||||
<add key="LeafWebUrl" value="http://192.168.1.133:61755/" />
|
||||
<add key="PiscalNotifyCompleteUrlPath" value="umbraco/surface/LeafInput/NotifyComplete" />
|
||||
<add key="LeafWebUrl" value="http://localhost:61755/" />
|
||||
<add key="PiscalNotifyCompleteUrlPath" value="notifycomplete" />
|
||||
<add key="ResultsDownloadPath" value="Results/Download?token={0}" />
|
||||
<add key="MemberVerifyPath" value="verify?email={0}&token={1}" />
|
||||
<add key="PiscalUnresponsiveHourCount" value="24" />
|
||||
</appSettings>
|
||||
<connectionStrings>
|
||||
@@ -344,7 +345,22 @@
|
||||
<requestLimits maxAllowedContentLength="1000000000" />
|
||||
</requestFiltering>
|
||||
</security>
|
||||
|
||||
<rewrite>
|
||||
<rules>
|
||||
<rule name="MembershipVerify" stopProcessing="true">
|
||||
<match url="^verify$" />
|
||||
<action type="Rewrite" url="/umbraco/surface/Membership/Verify" />
|
||||
</rule>
|
||||
<rule name="FluxnetSiteAutocomplete" stopProcessing="true">
|
||||
<match url="^FluxnetSiteAutocomplete$" />
|
||||
<action type="Rewrite" url="/umbraco/surface/FluxnetSite/Autocomplete" />
|
||||
</rule>
|
||||
<rule name="NotifyComplete" stopProcessing="true">
|
||||
<match url="^notifycomplete" />
|
||||
<action type="Rewrite" url="/umbraco/surface/LeafInput/NotifyComplete" />
|
||||
</rule>
|
||||
</rules>
|
||||
</rewrite>
|
||||
<validation validateIntegratedModeConfiguration="false" /></system.webServer>
|
||||
<runtime>
|
||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
|
||||
@@ -1098,6 +1098,7 @@
|
||||
<Compile Include="Controllers\ContactController.cs" />
|
||||
<Compile Include="Controllers\LeafInputController.cs" />
|
||||
<Compile Include="Controllers\LeafWebPageIds.cs" />
|
||||
<Compile Include="Controllers\MembershipController.cs" />
|
||||
<Compile Include="Controllers\QueueController.cs" />
|
||||
<Compile Include="Controllers\ResultsController.cs" />
|
||||
<Compile Include="EventHandlers\MemberEvents.cs" />
|
||||
|
||||
Reference in New Issue
Block a user