1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-01 08:02:49 -05:00

Adjusted two factor recovery model and moved functionality to user service

This commit is contained in:
Kyle Spearrin
2016-11-14 23:32:15 -05:00
parent 54a857f215
commit 4867df0138
4 changed files with 37 additions and 19 deletions

View File

@ -209,30 +209,15 @@ namespace Bit.Api.Controllers
return response;
}
[HttpPut("two-factor-recover")]
[HttpPost("two-factor-recover")]
public async Task<TwoFactorResponseModel> PutTwoFactorRecover([FromBody]RecoverTwoFactorRequestModel model)
[AllowAnonymous]
public async Task PostTwoFactorRecover([FromBody]RecoverTwoFactorRequestModel model)
{
var user = _currentContext.User;
if(!await _userManager.CheckPasswordAsync(user, model.MasterPasswordHash))
if(!await _userService.RecoverTwoFactorAsync(model.Email, model.MasterPasswordHash, model.RecoveryCode))
{
await Task.Delay(2000);
throw new BadRequestException("MasterPasswordHash", "Invalid password.");
throw new BadRequestException(string.Empty, "Invalid information. Try again.");
}
if(string.Compare(user.TwoFactorRecoveryCode, model.RecoveryCode, true) != 0)
{
await Task.Delay(2000);
throw new BadRequestException("RecoveryCode", "Invalid recovery code.");
}
user.TwoFactorProvider = TwoFactorProvider.Authenticator;
user.TwoFactorEnabled = false;
user.TwoFactorRecoveryCode = null;
await _userService.SaveUserAsync(user);
var response = new TwoFactorResponseModel(user);
return response;
}
[HttpPut("two-factor-regenerate")]

View File

@ -5,6 +5,10 @@ namespace Bit.Api.Models
{
public class RecoverTwoFactorRequestModel
{
[Required]
[EmailAddress]
[StringLength(50)]
public string Email { get; set; }
[Required]
public string MasterPasswordHash { get; set; }
[Required]