public async Task <ActionResult> AddUser(AddUserModel model) { if (!ModelState.IsValid) { return(AddUser()); } var(userId, result) = await _addUserCommand.Execute(model, UserManager); if (!result.Succeeded) { model.GlobalSettingsTabEnumerations = GetGlobalSettingsTabsWithUsersSelected(); AddErrors(result); return(View(model)); } _editUserRoleCommand.Execute(new EditUserRoleModel { UserId = userId, RoleId = Role.Admin.Value.ToString() }); SuccessToastMessage("New User added successfully. \n Please inform the user of the initial password."); return(RedirectToAction("Users", "GlobalSettings")); }
public async Task <ActionResult> Register(RegisterViewModel model) { if (!_applicationConfiguration.AllowUserRegistration()) { return(RedirectToAction("Login")); } if (ModelState.IsValid) { var(adminAppUser, result) = await _registerCommand.Execute(model, _userManager); if (result.Succeeded) { _editUserRoleCommand.Execute(new EditUserRoleModel { UserId = adminAppUser.Id, RoleId = Role.SuperAdmin.Value.ToString() }); await _signInManager.SignInAsync(adminAppUser, isPersistent : false); if (ZeroOdsInstanceRegistrations()) { return(RedirectToAction("RegisterOdsInstance", "OdsInstances")); } return(RedirectToAction("Index", "Home")); } AddErrors(result); } return(View(model)); }
public void ShouldEditUserRole() { var existingUsers = SetupUsers(2, Role.Admin).ToList(); var userToBeSuperAdmin = existingUsers[0]; var userToRemainAdmin = existingUsers[1]; var guidString = Guid.NewGuid().ToString("N"); var updateModel = new EditUserRoleModel { UserId = userToBeSuperAdmin.Id, RoleId = Role.SuperAdmin.Value.ToString() }; Scoped <AdminAppIdentityDbContext>(identity => { var command = new EditUserRoleCommand(identity); command.Execute(updateModel); }); Scoped <AdminAppIdentityDbContext>(identity => { var query = new GetRoleForUserQuery(identity); var editedUserRole = query.Execute(userToBeSuperAdmin.Id); editedUserRole.ShouldBe(Role.SuperAdmin); var notEditedUserRole = query.Execute(userToRemainAdmin.Id); notEditedUserRole.ShouldBe(Role.Admin); }); }
public async Task <ActionResult> Register(RegisterViewModel model) { if (!_applicationConfiguration.AllowUserRegistration()) { return(RedirectToAction("Login")); } if (ModelState.IsValid) { var(adminAppUser, result) = await _registerCommand.Execute(model, UserManager); if (result.Succeeded) { _editUserRoleCommand.Execute(new EditUserRoleModel { UserId = adminAppUser.Id, RoleId = Role.SuperAdmin.Value.ToString() }); await SignInManager.SignInAsync(adminAppUser, isPersistent : false, rememberBrowser : false); // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); // var callbackUrl = Url.Action("ConfirmEmail", "Identity", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); if (ZeroOdsInstanceRegistrations()) { return(RedirectToAction("RegisterOdsInstance", "OdsInstances")); } return(RedirectToAction("Index", "Home")); } AddErrors(result); } return(View(model)); }