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 <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)); }