mirror of
https://github.com/streetwriters/notesnook-sync-server.git
synced 2026-02-12 19:22:45 +00:00
identity: reset user 2fa on password reset
This commit is contained in:
@@ -302,6 +302,7 @@ namespace Streetwriters.Identity.Controllers
|
||||
var result = await UserManager.RemovePasswordAsync(user);
|
||||
if (result.Succeeded)
|
||||
{
|
||||
await MFAService.ResetMFAAsync(user);
|
||||
result = await UserManager.AddPasswordAsync(user, form.NewPassword);
|
||||
if (result.Succeeded)
|
||||
{
|
||||
|
||||
@@ -28,6 +28,7 @@ namespace Streetwriters.Identity.Interfaces
|
||||
{
|
||||
Task EnableMFAAsync(User user, string primaryMethod);
|
||||
Task<bool> DisableMFAAsync(User user);
|
||||
Task<bool> ResetMFAAsync(User user);
|
||||
Task SetSecondaryMethodAsync(User user, string secondaryMethod);
|
||||
string GetPrimaryMethod(User user);
|
||||
string GetSecondaryMethod(User user);
|
||||
|
||||
@@ -54,6 +54,7 @@ namespace Streetwriters.Identity.Services
|
||||
if (!result.Succeeded) return;
|
||||
|
||||
await this.RemovePrimaryMethodAsync(user);
|
||||
await this.RemoveSecondaryMethodAsync(user);
|
||||
await UserManager.AddClaimAsync(user, new Claim(MFAService.PRIMARY_METHOD_CLAIM, primaryMethod));
|
||||
}
|
||||
|
||||
@@ -69,6 +70,20 @@ namespace Streetwriters.Identity.Services
|
||||
return true;
|
||||
}
|
||||
|
||||
public async Task<bool> ResetMFAAsync(User user)
|
||||
{
|
||||
var result = await UserManager.SetTwoFactorEnabledAsync(user, false);
|
||||
var result = await UserManager.SetTwoFactorEnabledAsync(user, true);
|
||||
|
||||
await this.RemovePrimaryMethodAsync(user);
|
||||
await this.RemoveSecondaryMethodAsync(user);
|
||||
|
||||
await UserManager.AddClaimAsync(user, new Claim(MFAService.PRIMARY_METHOD_CLAIM, MFAMethods.Email));
|
||||
|
||||
await UserManager.ResetAuthenticatorKeyAsync(user);
|
||||
return true;
|
||||
}
|
||||
|
||||
public async Task SetSecondaryMethodAsync(User user, string secondaryMethod)
|
||||
{
|
||||
await this.ReplaceClaimAsync(user, MFAService.SECONDARY_METHOD_CLAIM, secondaryMethod);
|
||||
|
||||
Reference in New Issue
Block a user