public async Task<ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { // Create a local login before signing in the user var user = new ExtendedUser(model.UserName) { Email = model.Email, FirstName = model.FirstName, LastName = model.LastName }; var result = await IdentityManager.Users.CreateLocalUserAsync(user, model.Password); await AddUserToRole(user.Id, userRole); if (result.Success) { await IdentityManager.Authentication.SignInAsync(AuthenticationManager, user.Id, isPersistent: false); return RedirectToAction("Index", "Home"); } else { AddErrors(result); } } // If we got this far, something failed, redisplay form return View(model); }
public async Task<ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl) { if (User.Identity.IsAuthenticated) { return RedirectToAction("Manage"); } if (ModelState.IsValid) { var user = new ExtendedUser(model.UserName) { Email = model.Email, FirstName = model.FirstName, LastName = model.LastName }; // Get the information about the user from the external login provider IdentityResult result = await IdentityManager.Authentication .CreateAndSignInExternalUserAsync(AuthenticationManager, user); await AddUserToRole(user.Id, userRole); if (result.Success) { return RedirectToLocal(returnUrl); } else { AddErrors(result); } } ViewBag.ReturnUrl = returnUrl; return View(model); }