-
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.
- Loading branch information
0 parents
commit 09080ee
Showing
142 changed files
with
92,482 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,32 @@ | ||
@page | ||
|
||
@using Microsoft.AspNetCore.Authorization | ||
|
||
@model ConfirmEmailModel | ||
|
||
@{ | ||
ViewData["Title"] = "Confirm Email"; | ||
} | ||
|
||
<div class="dvh-70"> | ||
<h2>@ViewData["Title"]</h2> | ||
|
||
@if (Model.ShowSuccessMessage) | ||
{ | ||
<div class="alert alert-success"> | ||
Your email has been confirmed successfully. | ||
</div> | ||
} | ||
else if (Model.ShowErrorMessage) | ||
{ | ||
<div class="alert alert-danger"> | ||
Error confirming email. Please try again later or contact support. | ||
</div> | ||
} | ||
else | ||
{ | ||
<div> | ||
Validating your email confirmation... | ||
</div> | ||
} | ||
</div> |
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,60 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Mvc.RazorPages; | ||
using Microsoft.AspNetCore.Identity; | ||
using System.Threading.Tasks; | ||
using Project.Models; | ||
using Microsoft.AspNetCore.Authorization; | ||
using System.Text; | ||
using Microsoft.AspNetCore.WebUtilities; | ||
|
||
namespace Project.Areas.Identity.Pages.Account | ||
{ | ||
public class ConfirmEmailModel : PageModel | ||
{ | ||
private readonly UserManager<ApplicationUser> _userManager; | ||
|
||
public ConfirmEmailModel(UserManager<ApplicationUser> userManager) | ||
{ | ||
_userManager = userManager; | ||
} | ||
|
||
[BindProperty] | ||
public bool ShowSuccessMessage { get; set; } | ||
|
||
[BindProperty] | ||
public bool ShowErrorMessage { get; set; } | ||
|
||
public async Task<IActionResult> OnGetAsync(string userId, string code) | ||
{ | ||
if (userId == null || code == null) | ||
{ | ||
ShowErrorMessage = true; | ||
return Page(); | ||
} | ||
|
||
var user = await _userManager.FindByIdAsync(userId); | ||
if (user == null) | ||
{ | ||
ShowErrorMessage = true; | ||
return NotFound($"Unable to load user with id: '{userId}'."); | ||
} | ||
|
||
code = Encoding.UTF8.GetString(WebEncoders.Base64UrlDecode(code)); | ||
var result = await _userManager.ConfirmEmailAsync(user, code); | ||
|
||
// Console.WriteLine(result.Errors.FirstOrDefault()?.Code); | ||
// Console.WriteLine(result.Errors.FirstOrDefault()?.Description); | ||
|
||
if (result.Succeeded) | ||
{ | ||
ShowSuccessMessage = true; | ||
} | ||
else | ||
{ | ||
ShowErrorMessage = true; | ||
} | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
@page | ||
@model LoginModel | ||
|
||
@{ | ||
ViewData["Title"] = "Log In"; | ||
} | ||
|
||
<div id="signin-container" class="container"> | ||
<h1>@ViewData["Title"]</h1> | ||
<form class="d-flex flex-column gap-2" id="account" method="post"> | ||
<p class="text-secondary">New to OAuth App? | ||
<a asp-page="./Register" asp-route-returnUrl="@Model.ReturnUrl">Sign | ||
up for an account</a> | ||
</p> | ||
<div asp-validation-summary="ModelOnly" class="text-danger" role="alert"></div> | ||
<div class="form-floating mb-3"> | ||
<input asp-for="Input.Email" class="form-control" autocomplete="username" aria-required="true" | ||
placeholder="[email protected]" /> | ||
<label asp-for="Input.Email" class="form-label">Email</label> | ||
<span asp-validation-for="Input.Email" class="text-danger"></span> | ||
</div> | ||
<div class="form-floating mb-3"> | ||
<input asp-for="Input.Password" class="form-control" autocomplete="current-password" aria-required="true" | ||
placeholder="password" /> | ||
<label asp-for="Input.Password" class="form-label">Password</label> | ||
<span asp-validation-for="Input.Password" class="text-danger"></span> | ||
</div> | ||
<div class="d-flex justify-content-between"> | ||
<label asp-for="Input.RememberMe" class="form-label"> | ||
<input class="form-check-input" asp-for="Input.RememberMe" /> | ||
@Html.DisplayNameFor(m => m.Input.RememberMe) | ||
</label> | ||
<p> | ||
<a id="forgot-password" asp-page="./ForgotPassword">Forgot your password?</a> | ||
</p> | ||
</div> | ||
<div> | ||
<button id="login-submit" type="submit" class="w-100 btn btn-lg btn-outline-dark">Log In</button> | ||
</div> | ||
<div> | ||
<a id="resend-confirmation" asp-page="./ResendEmailConfirmation">Resend email confirmation</a> | ||
</div> | ||
</form> | ||
|
||
@{ | ||
if ((Model.ExternalLogins?.Count ?? 0) != 0) | ||
{ | ||
<div class="d-flex flex-row align-items-center my-2"> | ||
<hr class="flex-grow-4"> | ||
<span class="d-flex text-secondary flex-grow-1 justify-content-center">OR</span> | ||
<hr class="flex-grow-4"> | ||
</div> | ||
<form id="external-account" asp-page="./ExternalLogin" asp-route-returnUrl="@Model.ReturnUrl" method="post" | ||
class="form-horizontal"> | ||
<div> | ||
<p> | ||
@foreach (var provider in Model.ExternalLogins!) | ||
{ | ||
<button type="submit" class="btn btn-primary w-100 btn-lg mb-3" name="provider" value="@provider.Name" | ||
title="Log in using your @provider.DisplayName account">Continue with @provider.DisplayName</button> | ||
} | ||
</p> | ||
</div> | ||
</form> | ||
} | ||
} | ||
</div> | ||
|
||
|
||
@section Scripts { | ||
<partial name="_ValidationScriptsPartial" /> | ||
} | ||
|
||
<style scoped> | ||
#signin-container { | ||
padding: 0 300px; | ||
height: 70dvh; | ||
} | ||
.flex-grow-4 { | ||
flex-grow: 4; | ||
} | ||
</style> |
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,134 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
#nullable disable | ||
|
||
using System.ComponentModel.DataAnnotations; | ||
using Microsoft.AspNetCore.Authentication; | ||
using Microsoft.AspNetCore.Identity; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Mvc.RazorPages; | ||
using Project.Models; | ||
|
||
namespace Project.Areas.Identity.Pages.Account | ||
{ | ||
public class LoginModel : PageModel | ||
{ | ||
private readonly SignInManager<ApplicationUser> _signInManager; | ||
private readonly ILogger<LoginModel> _logger; | ||
|
||
public LoginModel(SignInManager<ApplicationUser> signInManager, ILogger<LoginModel> logger) | ||
{ | ||
_signInManager = signInManager; | ||
_logger = logger; | ||
} | ||
|
||
/// <summary> | ||
/// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used | ||
/// directly from your code. This API may change or be removed in future releases. | ||
/// </summary> | ||
[BindProperty] | ||
public InputModel Input { get; set; } | ||
|
||
/// <summary> | ||
/// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used | ||
/// directly from your code. This API may change or be removed in future releases. | ||
/// </summary> | ||
public IList<AuthenticationScheme> ExternalLogins { get; set; } | ||
|
||
/// <summary> | ||
/// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used | ||
/// directly from your code. This API may change or be removed in future releases. | ||
/// </summary> | ||
public string ReturnUrl { get; set; } | ||
|
||
/// <summary> | ||
/// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used | ||
/// directly from your code. This API may change or be removed in future releases. | ||
/// </summary> | ||
[TempData] | ||
public string ErrorMessage { get; set; } | ||
|
||
/// <summary> | ||
/// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used | ||
/// directly from your code. This API may change or be removed in future releases. | ||
/// </summary> | ||
public class InputModel | ||
{ | ||
/// <summary> | ||
/// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used | ||
/// directly from your code. This API may change or be removed in future releases. | ||
/// </summary> | ||
[Required] | ||
[EmailAddress] | ||
public string Email { get; set; } | ||
|
||
/// <summary> | ||
/// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used | ||
/// directly from your code. This API may change or be removed in future releases. | ||
/// </summary> | ||
[Required] | ||
[DataType(DataType.Password)] | ||
public string Password { get; set; } | ||
|
||
/// <summary> | ||
/// This API supports the ASP.NET Core Identity default UI infrastructure and is not intended to be used | ||
/// directly from your code. This API may change or be removed in future releases. | ||
/// </summary> | ||
[Display(Name = "Remember me?")] | ||
public bool RememberMe { get; set; } | ||
} | ||
|
||
public async Task OnGetAsync(string returnUrl = null) | ||
{ | ||
if (!string.IsNullOrEmpty(ErrorMessage)) | ||
{ | ||
ModelState.AddModelError(string.Empty, ErrorMessage); | ||
} | ||
|
||
returnUrl ??= Url.Content("~/"); | ||
|
||
// Clear the existing external cookie to ensure a clean login process | ||
await HttpContext.SignOutAsync(IdentityConstants.ExternalScheme); | ||
|
||
ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList(); | ||
|
||
ReturnUrl = returnUrl; | ||
} | ||
|
||
public async Task<IActionResult> OnPostAsync(string returnUrl = null) | ||
{ | ||
returnUrl ??= Url.Content("~/"); | ||
|
||
ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList(); | ||
|
||
if (ModelState.IsValid) | ||
{ | ||
var result = await _signInManager.PasswordSignInAsync(Input.Email, Input.Password, Input.RememberMe, lockoutOnFailure: false); | ||
if (result.Succeeded) | ||
{ | ||
_logger.LogInformation("User {Email} logged in successfully.", Input.Email); | ||
return LocalRedirect(returnUrl); | ||
} | ||
if (result.RequiresTwoFactor) | ||
{ | ||
_logger.LogInformation("User {Email} requires two-factor authentication.", Input.Email); | ||
return RedirectToPage("./LoginWith2fa", new { ReturnUrl = returnUrl, RememberMe = Input.RememberMe }); | ||
} | ||
if (result.IsLockedOut) | ||
{ | ||
_logger.LogWarning("User {Email} account is locked out.", Input.Email); | ||
return RedirectToPage("./Lockout"); | ||
} | ||
else | ||
{ | ||
_logger.LogWarning("Login attempt failed for user {Email}", Input.Email); | ||
ModelState.AddModelError(string.Empty, "Invalid login attempt."); | ||
return Page(); | ||
} | ||
} | ||
|
||
// If we got this far, something failed, redisplay form | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
@page | ||
@model LogoutModel | ||
@{ | ||
ViewData["Title"] = "Log out"; | ||
} | ||
|
||
<header> | ||
<h1>@ViewData["Title"]</h1> | ||
@{ | ||
if (User.Identity?.IsAuthenticated ?? false) | ||
{ | ||
<form class="form-inline" asp-area="Identity" asp-page="/Account/Logout" asp-route-returnUrl="@Url.Page("/", new { area = "" })" method="post"> | ||
<button type="submit" class="nav-link btn btn-link text-dark">Click here to Logout</button> | ||
</form> | ||
} | ||
else | ||
{ | ||
<p>You have successfully logged out of the application.</p> | ||
} | ||
} | ||
</header> |
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 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
#nullable disable | ||
|
||
using System; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Identity; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Mvc.RazorPages; | ||
using Microsoft.Extensions.Logging; | ||
using Project.Models; | ||
|
||
namespace Project.Areas.Identity.Pages.Account | ||
{ | ||
public class LogoutModel : PageModel | ||
{ | ||
private readonly SignInManager<ApplicationUser> _signInManager; | ||
private readonly ILogger<LogoutModel> _logger; | ||
|
||
public LogoutModel(SignInManager<ApplicationUser> signInManager, ILogger<LogoutModel> logger) | ||
{ | ||
_signInManager = signInManager; | ||
_logger = logger; | ||
} | ||
|
||
public async Task<IActionResult> OnPost(string returnUrl = null) | ||
{ | ||
await _signInManager.SignOutAsync(); | ||
_logger.LogInformation("User logged out."); | ||
if (returnUrl != null) | ||
{ | ||
return LocalRedirect(returnUrl); | ||
} | ||
else | ||
{ | ||
// This needs to be a redirect so that the browser performs a new | ||
// request and the identity for the user gets updated. | ||
return RedirectToPage(); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.