public IActionResult NewUser(userClaim User) { var result = CreateUser(User); // Redirects them to the Members area if successful; otherwise, reloads page and shows error if (result.Result.Succeeded) { return(RedirectToAction("Index", "Members")); } else { ViewBag.errors = result.Result.Errors; return(View()); } }
public async Task <IActionResult> ManageUserClaims(string userId) { var user = await userManager.FindByIdAsync(userId); if (user == null) { ViewBag.ErrorMessage = $"User with Id = {userId} cannot be found"; return(View("NotFound")); } // UserManager service, GetClaimsAsync method gets all the current claims of the user var claims = await userManager.GetClaimsAsync(user); var model = new UserClaimViewModel { UserId = userId }; // Loop through each claim we have in our application foreach (var claim in ClaimsStore.AllClaims) { userClaim userClaim = new userClaim { ClaimType = claim.Type }; // If the user has the claim, set IsSelected property to true, so the checkbox // next to the claim is checked on the UI if (claims.Any(c => c.Type == claim.Type && c.Value == "true")) { userClaim.IsSelected = true; } model.Claims.Add(userClaim); } return(View(model)); }
/// <summary> /// Attempts to create a new user and write it to the database using Usermanager /// </summary> /// <returns>Returns an IdentityResult</returns> public static async Task <IdentityResult> CreateUser(userClaim User) { User.UserName = User.FirstName + "_" + User.LastName; // WIP -- Hashing pass with 265 SHA IdentityResult result = await userManager.CreateAsync(User, User.password); ///////////////// REMOVE AFTER DEVELOPMENT COMPLETE /////////////////////// // Also: remove RoleManager in constructor and protected members // as well as the checkbox on the view if (User.admin) { IdentityRole admin = new IdentityRole("admin"); await roleManager.CreateAsync(admin); await userManager.AddToRoleAsync(User, "admin"); } return(result); }