public async Task <ActionResult> RecoveryCodes_Partial(EditModel model) { using (UserDefinitionDataProvider userDP = new UserDefinitionDataProvider()) { UserDefinition user = await userDP.GetItemByUserIdAsync(Manager.UserId); if (user == null) { throw new InternalError("User with id {0} not found", Manager.UserId); } EditModel.ModelProgressEnum progress = (EditModel.ModelProgressEnum)Manager.SessionSettings.SiteSettings.GetValue <int>(IDENTITY_RECOVERY_PROGRESS, (int)EditModel.ModelProgressEnum.New); model.ModelProgress = progress; model.UpdateData(user); if (!ModelState.IsValid) { return(PartialView(model)); } string msg = null; switch (progress) { case EditModel.ModelProgressEnum.New: progress = EditModel.ModelProgressEnum.ShowLogin; break; case EditModel.ModelProgressEnum.ShowLogin: #if MVC6 if (!await Managers.GetUserManager().CheckPasswordAsync(user, model.Password)) #else if (await Managers.GetUserManager().FindAsync(user.UserName, model.Password) == null) #endif { ModelState.AddModelError(nameof(model.Password), this.__ResStr("badPassword", "The password is invalid")); } if (!ModelState.IsValid) { return(PartialView(model)); } progress = EditModel.ModelProgressEnum.ShowCodes; break; case EditModel.ModelProgressEnum.ShowCodes: await GenerateRecoveryCodeAsync(userDP, user); msg = this.__ResStr("newCode", "A new recovery code has been generated"); break; } Manager.SessionSettings.SiteSettings.SetValue <int>(IDENTITY_RECOVERY_PROGRESS, (int)progress); Manager.SessionSettings.SiteSettings.Save(); model.ModelProgress = progress; model.UpdateData(user); return(FormProcessed(model, popupText: msg, ForceApply: true)); } }
public async Task <ActionResult> RecoveryCodes() { using (UserDefinitionDataProvider userDP = new UserDefinitionDataProvider()) { UserDefinition user = await userDP.GetItemByUserIdAsync(Manager.UserId); if (user == null) { throw new InternalError("User with id {0} not found", Manager.UserId); } // Make sure this user is not using an external account using (UserLoginInfoDataProvider logInfoDP = new UserLoginInfoDataProvider()) { if (await logInfoDP.IsExternalUserAsync(Manager.UserId)) { return(new EmptyResult()); } } // Make sure there are any 2fa processors TwoStepAuth twoStep = new TwoStepAuth(); List <ITwoStepAuth> list = await twoStep.GetTwoStepAuthProcessorsAsync(); if (list.Count == 0) { return(new EmptyResult()); } // If there is no recovery code, generate one (upgraded system) if (user.RecoveryCode == null) { await GenerateRecoveryCodeAsync(userDP, user); } EditModel.ModelProgressEnum progress = (EditModel.ModelProgressEnum)Manager.SessionSettings.SiteSettings.GetValue <int>(IDENTITY_RECOVERY_PROGRESS, (int)EditModel.ModelProgressEnum.New); EditModel model = new EditModel() { ModelProgress = progress, }; model.UpdateData(user); await Manager.AddOnManager.AddAddOnNamedAsync("YetaWF_ComponentsHTML", "clipboardjs.com.clipboard");// add clipboard support which is needed later (after partial form update) return(View(model)); } }