public async Task <IActionResult> Register(RegisterModel model) { if (!ModelState.IsValid) { return(View(model)); } var user = new ExtendedIdentityUserModel(model.Username) { UserName = model.Username, FirstName = model.FirstName, LastName = model.LastName, Email = model.Email }; var result = await _userManager.CreateAsync(user, model.Password); if (result.Succeeded) { await _signInManager.SignInAsync(user, false); return(RedirectToAction("Welcome", "Home")); } return(View()); }
public static void Main(string[] args) { var host = CreateWebHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var userManager = scope.ServiceProvider .GetRequiredService <UserManager <ExtendedIdentityUserModel> >(); var user = new ExtendedIdentityUserModel("sanket"); userManager.CreateAsync(user, "password").GetAwaiter().GetResult(); } host.Run(); }
public async Task <IActionResult> UpdateUser(EditUserModel mod) { ExtendedIdentityUserModel user = new ExtendedIdentityUserModel(mod.FirstName); //user.UserName = User.Identity.Name; user.FirstName = mod.FirstName; user.LastName = mod.LastName; user.Email = mod.Email; user.PasswordHash = mod.Password; user.SecurityStamp = Guid.NewGuid().ToString("D"); var result = await _userManager.UpdateAsync(user); if (result.Succeeded) { return(RedirectToAction("Welcome", "Home")); } else { ModelState.AddModelError("", "Error Occurred while editing details..."); } return(View(mod)); }