Skip to content

Commit

Permalink
New forgot password page and confirmation
Browse files Browse the repository at this point in the history
  • Loading branch information
nwrxi committed Nov 1, 2020
1 parent ff64626 commit 287311b
Show file tree
Hide file tree
Showing 7 changed files with 163 additions and 14 deletions.
37 changes: 37 additions & 0 deletions SginalRChatTest/Areas/Identity/Pages/Account/ForgotPassword.cshtml
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" />
}
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();
}
}
}
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>
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()
{
}
}
}
4 changes: 1 addition & 3 deletions SginalRChatTest/Areas/Identity/Pages/Account/Register.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@
</div>

<div class="form-group">
<p>
<button class="btn btn-lg btn-primary btn-block text-uppercase button-signin" type="submit">Sign Up</button>
</p>
<button class="btn btn-lg btn-primary btn-block text-uppercase button-signin" type="submit">Sign Up</button>
</div>
</form>
</section>
Expand Down
22 changes: 15 additions & 7 deletions SginalRChatTest/Pages/Index.cshtml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
@page
<link rel="stylesheet" href="~/css/chat.css">
<link rel="stylesheet" href="~/css/font-awesome.min.css">
@section Styles
{
<link rel="stylesheet" href="~/css/chat.css">
<link rel="stylesheet" href="~/css/font-awesome.min.css">
}

<div class="container py-5 px-2">
<div class="row rounded-lg overflow-hidden shadow">
<!-- Chat Box-->
Expand All @@ -23,8 +27,12 @@
</div>
</div>

<script src="~/js/signalr/dist/browser/signalr.js"></script>
<script src="~/js/chat.js"></script>
<script>
var currentUser = "@HttpContext.User.Identity.Name";
</script>
@section Scripts
{
<script src="~/js/signalr/dist/browser/signalr.js"></script>
<script src="~/js/chat.js"></script>
<script>
var currentUser = "@HttpContext.User.Identity.Name";
</script>
}

8 changes: 4 additions & 4 deletions SginalRChatTest/SginalRChatTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="3.1.8" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="3.1.8" />
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="3.1.8" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="3.1.9" />
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="3.1.9" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="3.1.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.8">
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.9" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.9">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down

0 comments on commit 287311b

Please sign in to comment.