forked from nwrxi/SignalRChatTest
-
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.
New forgot password page and confirmation
- Loading branch information
Showing
7 changed files
with
163 additions
and
14 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
SginalRChatTest/Areas/Identity/Pages/Account/ForgotPassword.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,37 @@ | ||
@page | ||
@model ForgotPasswordModel | ||
|
||
@section Styles | ||
{ | ||
<link rel="stylesheet" href="~/css/login.css" /> | ||
} | ||
|
||
<div class="container"> | ||
<div class="row"> | ||
<div class="col-sm-9 col-md-7 col-lg-5 mx-auto"> | ||
<div class="card card-signin my-5"> | ||
<div class="card-body"> | ||
<h5 class="card-title text-center">Enter you email</h5> | ||
<section> | ||
<form class="form-signin" method="post"> | ||
<div class="form-label-group"> | ||
<input type="email" asp-for="Input.Email" class="form-control" placeholder="Email address" required autofocus> | ||
<label asp-for="Input.Email">Email address</label> | ||
<span asp-validation-for="Input.Email" class="text-danger"></span> | ||
</div> | ||
<div class="form-group"> | ||
<button class="btn btn-lg btn-primary btn-block text-uppercase button-signin" type="submit">Submit</button> | ||
</div> | ||
</form> | ||
</section> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
|
||
|
||
@section Scripts { | ||
<partial name="_ValidationScriptsPartial" /> | ||
} |
70 changes: 70 additions & 0 deletions
70
SginalRChatTest/Areas/Identity/Pages/Account/ForgotPassword.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,70 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel.DataAnnotations; | ||
using System.Text.Encodings.Web; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Identity; | ||
using Microsoft.AspNetCore.Identity.UI.Services; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Mvc.RazorPages; | ||
using Microsoft.AspNetCore.WebUtilities; | ||
|
||
namespace SginalRChatTest.Areas.Identity.Pages.Account | ||
{ | ||
[AllowAnonymous] | ||
public class ForgotPasswordModel : PageModel | ||
{ | ||
private readonly UserManager<IdentityUser> _userManager; | ||
private readonly IEmailSender _emailSender; | ||
|
||
public ForgotPasswordModel(UserManager<IdentityUser> userManager, IEmailSender emailSender) | ||
{ | ||
_userManager = userManager; | ||
_emailSender = emailSender; | ||
} | ||
|
||
[BindProperty] | ||
public InputModel Input { get; set; } | ||
|
||
public class InputModel | ||
{ | ||
[Required] | ||
[EmailAddress] | ||
public string Email { get; set; } | ||
} | ||
|
||
public async Task<IActionResult> OnPostAsync() | ||
{ | ||
if (ModelState.IsValid) | ||
{ | ||
var user = await _userManager.FindByEmailAsync(Input.Email); | ||
if (user == null || !(await _userManager.IsEmailConfirmedAsync(user))) | ||
{ | ||
// Don't reveal that the user does not exist or is not confirmed | ||
return RedirectToPage("./ForgotPasswordConfirmation"); | ||
} | ||
|
||
// For more information on how to enable account confirmation and password reset please | ||
// visit https://go.microsoft.com/fwlink/?LinkID=532713 | ||
var code = await _userManager.GeneratePasswordResetTokenAsync(user); | ||
code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code)); | ||
var callbackUrl = Url.Page( | ||
"/Account/ResetPassword", | ||
pageHandler: null, | ||
values: new { area = "Identity", code }, | ||
protocol: Request.Scheme); | ||
|
||
await _emailSender.SendEmailAsync( | ||
Input.Email, | ||
"Reset Password", | ||
$"Please reset your password by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>."); | ||
|
||
return RedirectToPage("./ForgotPasswordConfirmation"); | ||
} | ||
|
||
return Page(); | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
SginalRChatTest/Areas/Identity/Pages/Account/ForgotPasswordConfirmation.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,20 @@ | ||
@page | ||
@model ForgotPasswordConfirmation | ||
|
||
@section Styles | ||
{ | ||
<link rel="stylesheet" href="~/css/login.css" /> | ||
} | ||
|
||
|
||
<div class="container"> | ||
<div class="row"> | ||
<div class="col-sm-8 col-md-7 col-lg-10 mx-auto"> | ||
<div class="card card-signin my-5"> | ||
<div class="card-body"> | ||
<h5 class="card-title text-center"><br/>Please check your inbox. If this account exists we've sent you an email.</h5> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> |
16 changes: 16 additions & 0 deletions
16
SginalRChatTest/Areas/Identity/Pages/Account/ForgotPasswordConfirmation.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,16 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Mvc.RazorPages; | ||
|
||
namespace SginalRChatTest.Areas.Identity.Pages.Account | ||
{ | ||
[AllowAnonymous] | ||
public class ForgotPasswordConfirmation : PageModel | ||
{ | ||
public void OnGet() | ||
{ | ||
} | ||
} | ||
} |
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
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
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