Skip to content
This repository has been archived by the owner on Jun 9, 2022. It is now read-only.

Commit

Permalink
✨ Scaffolds email service
Browse files Browse the repository at this point in the history
  • Loading branch information
esentis committed Apr 25, 2021
1 parent 1f29961 commit dd54914
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/Ieemdb.Web/Controllers/AccountController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace Esentis.Ieemdb.Web.Controllers
using System.Security.Claims;
using System.Text;
using System.Threading.Tasks;
using System.Web;

using Esentis.Ieemdb.Persistence;
using Esentis.Ieemdb.Persistence.Helpers;
Expand Down Expand Up @@ -70,9 +71,11 @@ public async Task<ActionResult> RegisterUser([FromBody] UserRegisterDto userRegi
var result = await userManager.CreateAsync(user, userRegister.Password);

var token = await userManager.GenerateEmailConfirmationTokenAsync(user);
var url = HttpUtility.HtmlEncode(
$"{Request.Scheme}://{Request.Host}{Request.PathBase}/api/account/confirm?email={userRegister.Email}&token={token}");
var body = await renderer.RenderViewToStringAsync(
"/Views/Emails/ConfirmAccountEmail.cshtml",
new ConfirmAccountViewModel { ConfirmUrl = token, });
new ConfirmAccountViewModel { ConfirmUrl = url, });
await emailSender.SendEmailAsync(user.Email, "Email Confirmation", body);

await userManager.AddToRoleAsync(user, RoleNames.Member);
Expand All @@ -81,10 +84,11 @@ public async Task<ActionResult> RegisterUser([FromBody] UserRegisterDto userRegi
: Ok();
}

[AllowAnonymous]
[HttpPost("confirm")]
public async Task<ActionResult> ConfirmEmail(string emall, string token)
public async Task<ActionResult> ConfirmEmail(string email, string token)
{
var user = await userManager.FindByEmailAsync(emall);
var user = await userManager.FindByEmailAsync(email);
var result = await userManager.ConfirmEmailAsync(user, token);

return !result.Succeeded
Expand Down

0 comments on commit dd54914

Please sign in to comment.