-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add confirm email page(o2-auth)
Merge pull request #98 from live-dev999/live-dev999/issue97
- Loading branch information
Showing
3 changed files
with
59 additions
and
1 deletion.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
src/Services/auth/O2NextGen.Auth.Web/Pages/Account/ConfirmEmail.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
43 changes: 43 additions & 0 deletions
43
src/Services/auth/O2NextGen.Auth.Web/Pages/Account/ConfirmEmail.cshtml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters