Skip to content

Commit

Permalink
Ensure requirement is removed if they reset thru other means.
Browse files Browse the repository at this point in the history
  • Loading branch information
VasilisThePikachu committed Jun 26, 2024
1 parent 6ac37e5 commit 7e0078a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,16 @@ await _accountLogManager.LogAndSave(
new AccountLogEmailChanged(oldEmail, email),
_accountLogManager.ActorWithIP(user));

if (user.RequireEmailChange)
{
user.RequireEmailChange = false;
await _userManager.UpdateAsync(user);
}

await tx.CommitAsync();

await _signInManager.RefreshSignInAsync(user);
StatusMessage = "Thank you for confirming your email change.";
return Page();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ public async Task<IActionResult> OnPostAsync()
await _logManager.LogAndSave(user, new AccountLogPasswordChanged());
await _sessionManager.InvalidateSessions(user);
await _signInManager.RefreshSignInAsync(user);
if (user.RequirePasswordChange)
{
user.RequirePasswordChange = false;
await _userManager.UpdateAsync(user);
}
_logger.LogInformation("User changed their password successfully.");
StatusMessage = "Your password has been changed.";

Expand Down
13 changes: 9 additions & 4 deletions SS14.Web/Areas/Identity/Pages/Account/ResetPassword.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public async Task<IActionResult> OnPostAsync()
}

await using var tx = await _dbContext.Database.BeginTransactionAsync();

var user = await _userManager.FindByEmailAsync(Input.Email);
if (user == null)
{
Expand All @@ -85,11 +85,16 @@ public async Task<IActionResult> OnPostAsync()

if (result.Succeeded)
{
if (user.RequirePasswordChange)
{
user.RequirePasswordChange = false;
await _userManager.UpdateAsync(user);
}
await _logManager.LogAndSave(user, new AccountLogPasswordChanged(), _logManager.ActorWithIP(user));
}

await tx.CommitAsync();

if (result.Succeeded)
{
return RedirectToPage("./ResetPasswordConfirmation");
Expand All @@ -101,4 +106,4 @@ public async Task<IActionResult> OnPostAsync()
}
return Page();
}
}
}

0 comments on commit 7e0078a

Please sign in to comment.