From 570012b25bb3fe4ac50e500d1bc886b86c05af53 Mon Sep 17 00:00:00 2001 From: Denis Prokhorchik Date: Sat, 20 Nov 2021 11:30:15 +0300 Subject: [PATCH] issue-97: add confirm page(o2-auth) --- .../Pages/Account/ConfirmEmail.cshtml | 12 ++++++ .../Pages/Account/ConfirmEmail.cshtml.cs | 43 +++++++++++++++++++ .../auth/O2NextGen.Auth.Web/Startup.cs | 5 ++- 3 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 src/Services/auth/O2NextGen.Auth.Web/Pages/Account/ConfirmEmail.cshtml create mode 100644 src/Services/auth/O2NextGen.Auth.Web/Pages/Account/ConfirmEmail.cshtml.cs diff --git a/src/Services/auth/O2NextGen.Auth.Web/Pages/Account/ConfirmEmail.cshtml b/src/Services/auth/O2NextGen.Auth.Web/Pages/Account/ConfirmEmail.cshtml new file mode 100644 index 00000000..7644f84c --- /dev/null +++ b/src/Services/auth/O2NextGen.Auth.Web/Pages/Account/ConfirmEmail.cshtml @@ -0,0 +1,12 @@ +@page +@model ConfirmEmailModel +@{ + ViewData["Title"] = "Confirm email"; +} + +

@ViewData["Title"]

+
+

+ Thank you for confirming your email. +

+
diff --git a/src/Services/auth/O2NextGen.Auth.Web/Pages/Account/ConfirmEmail.cshtml.cs b/src/Services/auth/O2NextGen.Auth.Web/Pages/Account/ConfirmEmail.cshtml.cs new file mode 100644 index 00000000..e20e0b01 --- /dev/null +++ b/src/Services/auth/O2NextGen.Auth.Web/Pages/Account/ConfirmEmail.cshtml.cs @@ -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 _userManager; + + public ConfirmEmailModel(UserManager userManager) + { + _userManager = userManager; + } + + public async Task 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(); + } + } +} diff --git a/src/Services/auth/O2NextGen.Auth.Web/Startup.cs b/src/Services/auth/O2NextGen.Auth.Web/Startup.cs index a6de3e13..56f8299b 100644 --- a/src/Services/auth/O2NextGen.Auth.Web/Startup.cs +++ b/src/Services/auth/O2NextGen.Auth.Web/Startup.cs @@ -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; @@ -59,6 +61,7 @@ public DummyEmailSender(ILogger 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; } }