mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-08-09 13:28:39 +00:00
Add password reset page
This commit is contained in:
parent
be0591f4c3
commit
fa8e7a6b24
5 changed files with 86 additions and 44 deletions
36
ProjectLighthouse/Pages/PasswordResetPage.cshtml
Normal file
36
ProjectLighthouse/Pages/PasswordResetPage.cshtml
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
@page "/passwordReset"
|
||||||
|
@model LBPUnion.ProjectLighthouse.Pages.PasswordResetPage
|
||||||
|
|
||||||
|
@{
|
||||||
|
Layout = "Layouts/BaseLayout";
|
||||||
|
}
|
||||||
|
|
||||||
|
<script src="https://geraintluff.github.io/sha256/sha256.min.js"></script>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
function onSubmit(form) {
|
||||||
|
const password = form['password'];
|
||||||
|
const confirmPassword = form['confirmPassword'];
|
||||||
|
|
||||||
|
password.value = sha256(password.value);
|
||||||
|
confirmPassword.value = sha256(confirmPassword.value);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<h1>Password Reset</h1>
|
||||||
|
|
||||||
|
<form onsubmit="return onSubmit(this)">
|
||||||
|
<div class="ui left labeled input">
|
||||||
|
<label for="password" class="ui blue label">Password: </label>
|
||||||
|
<input type="password" name="password" id="password">
|
||||||
|
</div><br><br>
|
||||||
|
|
||||||
|
<div class="ui left labeled input">
|
||||||
|
<label for="password" class="ui blue label">Confirm Password: </label>
|
||||||
|
<input type="password" name="confirmPassword" id="confirmPassword">
|
||||||
|
</div><br><br><br>
|
||||||
|
|
||||||
|
<input type="submit" value="Reset password and continue" id="submit" class="ui green button"><br>
|
||||||
|
</form>
|
38
ProjectLighthouse/Pages/PasswordResetPage.cshtml.cs
Normal file
38
ProjectLighthouse/Pages/PasswordResetPage.cshtml.cs
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
#nullable enable
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using LBPUnion.ProjectLighthouse.Helpers;
|
||||||
|
using LBPUnion.ProjectLighthouse.Pages.Layouts;
|
||||||
|
using LBPUnion.ProjectLighthouse.Types;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace LBPUnion.ProjectLighthouse.Pages
|
||||||
|
{
|
||||||
|
public class PasswordResetPage : BaseLayout
|
||||||
|
{
|
||||||
|
public PasswordResetPage(Database database) : base(database)
|
||||||
|
{}
|
||||||
|
|
||||||
|
public bool WasResetRequest { get; private set; }
|
||||||
|
public async Task<IActionResult> OnGet([FromQuery] string password, [FromQuery] string confirmPassword)
|
||||||
|
{
|
||||||
|
User? user = this.Database.UserFromWebRequest(this.Request);
|
||||||
|
if (user == null) return this.Redirect("~/login");
|
||||||
|
|
||||||
|
this.WasResetRequest = !string.IsNullOrEmpty(password) && !string.IsNullOrEmpty(confirmPassword);
|
||||||
|
|
||||||
|
if (this.WasResetRequest)
|
||||||
|
{
|
||||||
|
if (password != confirmPassword) return this.BadRequest();
|
||||||
|
|
||||||
|
user.Password = HashHelper.BCryptHash(password);
|
||||||
|
user.PasswordResetRequired = false;
|
||||||
|
|
||||||
|
await this.Database.SaveChangesAsync();
|
||||||
|
|
||||||
|
return this.Redirect("~/");
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.Page();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,33 +5,9 @@
|
||||||
Layout = "Layouts/BaseLayout";
|
Layout = "Layouts/BaseLayout";
|
||||||
}
|
}
|
||||||
|
|
||||||
<script src="https://geraintluff.github.io/sha256/sha256.min.js"></script>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
function onSubmit(form) {
|
|
||||||
const password = form['password'];
|
|
||||||
const confirmPassword = form['confirmPassword'];
|
|
||||||
|
|
||||||
password.value = sha256(password.value);
|
|
||||||
confirmPassword.value = sha256(confirmPassword.value);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<h1>Password Reset Required</h1>
|
<h1>Password Reset Required</h1>
|
||||||
<p>An admin has deemed it necessary that you reset your password. Please do so.</p>
|
<p>An admin has deemed it necessary that you reset your password. Please do so.</p>
|
||||||
|
|
||||||
<form onsubmit="return onSubmit(this)">
|
<a href="/passwordReset">
|
||||||
<div class="ui left labeled input">
|
<div class="ui blue button">Reset Password</div>
|
||||||
<label for="password" class="ui blue label">Password: </label>
|
</a>
|
||||||
<input type="password" name="password" id="password">
|
|
||||||
</div><br><br>
|
|
||||||
|
|
||||||
<div class="ui left labeled input">
|
|
||||||
<label for="password" class="ui blue label">Confirm Password: </label>
|
|
||||||
<input type="password" name="confirmPassword" id="confirmPassword">
|
|
||||||
</div><br><br><br>
|
|
||||||
|
|
||||||
<input type="submit" value="Reset password and continue" id="submit" class="ui green button"><br>
|
|
||||||
</form>
|
|
|
@ -1,7 +1,6 @@
|
||||||
#nullable enable
|
#nullable enable
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using LBPUnion.ProjectLighthouse.Helpers;
|
|
||||||
using LBPUnion.ProjectLighthouse.Pages.Layouts;
|
using LBPUnion.ProjectLighthouse.Pages.Layouts;
|
||||||
using LBPUnion.ProjectLighthouse.Types;
|
using LBPUnion.ProjectLighthouse.Types;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
@ -15,25 +14,11 @@ namespace LBPUnion.ProjectLighthouse.Pages
|
||||||
|
|
||||||
public bool WasResetRequest { get; private set; }
|
public bool WasResetRequest { get; private set; }
|
||||||
|
|
||||||
public async Task<IActionResult> OnGet([FromQuery] string password, [FromQuery] string confirmPassword)
|
public async Task<IActionResult> OnGet()
|
||||||
{
|
{
|
||||||
User? user = this.Database.UserFromWebRequest(this.Request);
|
User? user = this.Database.UserFromWebRequest(this.Request);
|
||||||
if (user == null) return this.Redirect("~/login");
|
if (user == null) return this.Redirect("~/login");
|
||||||
if (!user.PasswordResetRequired) return this.Redirect("~/resetPassword");
|
if (!user.PasswordResetRequired) return this.Redirect("~/passwordReset");
|
||||||
|
|
||||||
this.WasResetRequest = !string.IsNullOrEmpty(password) && !string.IsNullOrEmpty(confirmPassword);
|
|
||||||
|
|
||||||
if (this.WasResetRequest)
|
|
||||||
{
|
|
||||||
if (password != confirmPassword) return this.BadRequest();
|
|
||||||
|
|
||||||
user.Password = HashHelper.BCryptHash(password);
|
|
||||||
user.PasswordResetRequired = false;
|
|
||||||
|
|
||||||
await this.Database.SaveChangesAsync();
|
|
||||||
|
|
||||||
return this.Redirect("~/");
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.Page();
|
return this.Page();
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,6 +40,13 @@
|
||||||
</a>
|
</a>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@if (Model.ProfileUser == Model.User)
|
||||||
|
{
|
||||||
|
<a class="ui blue button" href="/passwordReset">
|
||||||
|
<i class="key icon"></i>
|
||||||
|
<span>Reset Password</span>
|
||||||
|
</a>
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
<div class="eight wide column">
|
<div class="eight wide column">
|
||||||
<div class="ui blue segment">
|
<div class="ui blue segment">
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue