Skip to content

Commit

Permalink
feat: add confirm email page(o2-auth)
Browse files Browse the repository at this point in the history
Merge pull request #98 from live-dev999/live-dev999/issue97
  • Loading branch information
live-dev999 committed Nov 20, 2021
2 parents 0b36e2e + 570012b commit f715d76
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@page
@model ConfirmEmailModel
@{
ViewData["Title"] = "Confirm email";
}

<h1>@ViewData["Title"]</h1>
<div>
<p>
Thank you for confirming your email.
</p>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using O2NextGen.Auth.Web.Data;

namespace O2NextGen.Auth.Web.Pages.Account
{
[AllowAnonymous]
public class ConfirmEmailModel : PageModel
{
private readonly UserManager<O2User> _userManager;

public ConfirmEmailModel(UserManager<O2User> userManager)
{
_userManager = userManager;
}

public async Task<IActionResult> OnGetAsync(string userId, string code)
{
if (userId == null || code == null)
{
return RedirectToPage("/Index");
}

var user = await _userManager.FindByIdAsync(userId);
if (user == null)
{
return NotFound($"Unable to load user with ID '{userId}'.");
}

var result = await _userManager.ConfirmEmailAsync(user, code);
if (!result.Succeeded)
{
throw new InvalidOperationException($"Error confirming email for user with ID '{userId}':");
}

return Page();
}
}
}
5 changes: 4 additions & 1 deletion src/Services/auth/O2NextGen.Auth.Web/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Threading.Tasks;
using System.Text.Encodings.Web;
using System.Threading.Tasks;
using System.Web;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Identity;
Expand Down Expand Up @@ -59,6 +61,7 @@ public DummyEmailSender(ILogger<DummyEmailSender> logger)
public Task SendEmailAsync(string email, string subject, string htmlMessage)
{
_logger.LogWarning("EmailSender implementation is being used!!!!");
_logger.LogWarning($"htmlMessage = { HttpUtility.HtmlDecode(htmlMessage)}");
return Task.CompletedTask;
}
}
Expand Down

0 comments on commit f715d76

Please sign in to comment.