public async Task <ActionResult> SelectTwoStepSetup() { EditModel model = new EditModel(); Manager.NeedUser(); 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); } using (UserLoginInfoDataProvider logInfoDP = new UserLoginInfoDataProvider()) { string ext = await logInfoDP.GetExternalLoginProviderAsync(Manager.UserId); if (ext != null) { return(View("ShowMessage", this.__ResStr("extUser", "Your account uses a {0} account - Two-step authentication must be set up using your {0} account.", ext), UseAreaViewName: false)); } } TwoStepAuth twoStep = new TwoStepAuth(); List <ITwoStepAuth> list = await twoStep.GetTwoStepAuthProcessorsAsync(); List <string> procs = (from p in list select p.Name).ToList(); List <string> enabledTwoStepAuths = (from e in user.EnabledTwoStepAuthentications select e.Name).ToList(); foreach (string proc in procs) { ITwoStepAuth auth = await twoStep.GetTwoStepAuthProcessorByNameAsync(proc); if (auth != null) { ModuleAction action = await auth.GetSetupActionAsync(); if (action != null) { string status; if (enabledTwoStepAuths.Contains(auth.Name)) { status = this.__ResStr("enabled", "(Enabled)"); } else { status = this.__ResStr("notEnabled", "(Not Enabled)"); } model.AuthMethods.Add(new Controllers.SelectTwoStepSetupModuleController.EditModel.AuthMethod { Action = action, Status = status, Description = auth.GetDescription() }); } } } model.AuthMethods = (from a in model.AuthMethods orderby a.Action.LinkText select a).ToList(); } return(View(model)); }
public async Task <List <string> > GetEnabledAndAvailableTwoStepAuthenticationsAsync() { TwoStepAuth twoStep = new TwoStepAuth(); List <ITwoStepAuth> list = await twoStep.GetTwoStepAuthProcessorsAsync(); List <string> procs = (from p in list select p.Name).ToList(); List <string> enabledTwoStepAuths = (from e in EnabledTwoStepAuthentications select e.Name).ToList(); procs = procs.Intersect(enabledTwoStepAuths).ToList(); return(procs); }
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)); } }
public async Task <ActionResult> SelectTwoStepAuth(int userId, string userName, string userEmail) { EditModel model = new EditModel { UserId = userId, UserName = userName, UserEmail = userEmail, }; using (UserDefinitionDataProvider userDP = new UserDefinitionDataProvider()) { UserDefinition user = await userDP.GetItemByUserIdAsync(userId); if (user == null) { throw new InternalError("User with id {0} not found", userId); } TwoStepAuth twoStep = new TwoStepAuth(); List <ITwoStepAuth> list = await twoStep.GetTwoStepAuthProcessorsAsync(); List <string> procs = (from p in list select p.Name).ToList(); List <string> enabledTwoStepAuths = (from e in user.EnabledTwoStepAuthentications select e.Name).ToList(); procs = procs.Intersect(enabledTwoStepAuths).ToList(); foreach (string proc in procs) { ITwoStepAuth auth = await twoStep.GetTwoStepAuthProcessorByNameAsync(proc); if (auth != null) { model.Actions.New(await auth.GetLoginActionAsync(userId, userName, userEmail)); } } if (model.Actions.Count == 0) { throw new InternalError("There are no two-step authentication providers installed"); } } return(View(model)); }