Add VerificationToken for new members

This commit is contained in:
2019-12-16 14:42:55 -05:00
parent 7a4946f4f4
commit 0139d66d63
10 changed files with 130 additions and 63 deletions
-22
View File
@@ -1,22 +0,0 @@
using System.Configuration;
using LeafWeb.Core.Entities;
namespace LeafWeb.WebCms.Services
{
public class DownloadUrlService
{
private readonly string _downloadUrl;
public DownloadUrlService()
{
_downloadUrl =
ConfigurationManager.AppSettings["LeafWebUrl"]
+ ConfigurationManager.AppSettings["ResultsDownloadPath"];
}
public string GetDownloadUrl(LeafInput leafInput)
{
return string.Format(_downloadUrl, leafInput.UniqueToken);
}
}
}
+18 -7
View File
@@ -7,7 +7,11 @@ using LeafWeb.Core.DAL;
using LeafWeb.Core.Entities;
using LeafWeb.Core.Utility;
using LeafWeb.WebCms.Models;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Web;
using Umbraco.Web.PublishedCache;
using Umbraco.Web.Security;
namespace LeafWeb.WebCms.Services
{
@@ -32,7 +36,7 @@ namespace LeafWeb.WebCms.Services
private readonly DataService _dataService;
private readonly DownloadUrlService _downloadUrlService;
private readonly UrlService _urlService;
private string FormatSubject(string subject, LeafInput leafInput)
{
@@ -43,7 +47,7 @@ namespace LeafWeb.WebCms.Services
{
_dataService = dataService;
_downloadUrlService = new DownloadUrlService();
_urlService = new UrlService();
_smtpClient = new SmtpClient(
ConfigurationManager.AppSettings["SmtpHost"],
@@ -114,7 +118,7 @@ namespace LeafWeb.WebCms.Services
if (downloadLink)
{
var downloadUrl = _downloadUrlService.GetDownloadUrl(leafInput);
var downloadUrl = _urlService.GetDownloadUrl(leafInput);
body +=
"Download results with the following link:"
@@ -197,12 +201,18 @@ namespace LeafWeb.WebCms.Services
SendMessage(message);
}
public void SendVerifyMemberEmail(IMember member)
public void SendVerifyMemberEmail(string memberEmail)
{
// TODO: write verify email to user
var servicesMemberService = ApplicationContext.Current.Services.MemberService;
var member = servicesMemberService.GetByEmail(memberEmail);
var verifyEmailURl = _urlService.GetVerifyEmailURl(member);
var body = "Please verify your email address with this link " + verifyEmailURl;
var message = new MailMessage(_emailFromAddress, member.Email, "Verify your email for LeafWeb", body);
SendMessage(message);
}
private string FormatWarningMessage(LeafInput leafInput)
private string FormatWarningMessage(LeafInput leafInput)
{
if (leafInput.OutputWarningMessage != null)
return Environment.NewLine + Environment.NewLine
@@ -230,5 +240,6 @@ namespace LeafWeb.WebCms.Services
{
_dataService.Dispose();
}
}
}
}
+33
View File
@@ -0,0 +1,33 @@
using System.Configuration;
using LeafWeb.Core.Entities;
using Umbraco.Core.Models;
using Umbraco.Web.PublishedCache;
namespace LeafWeb.WebCms.Services
{
public class UrlService
{
private readonly string _downloadUrl;
private readonly string _verifyEmailUrl;
public UrlService()
{
_downloadUrl =
ConfigurationManager.AppSettings["LeafWebUrl"]
+ ConfigurationManager.AppSettings["ResultsDownloadPath"];
}
public string GetDownloadUrl(LeafInput leafInput)
{
return string.Format(_downloadUrl, leafInput.UniqueToken);
}
public string GetVerifyEmailURl(IMember member)
{
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);
}
}
}