public async Task<ActionResult> Create(CreateUserModel model) { if (!ModelState.IsValid) return View(model); var user = new User { UserName = model.UserName, Email = model.Email, Profile = { FisrtName = model.FirstName, LastName = model.LastName, NationalCode = model.NationalCode } }; var result = await AppUserManager.CreateAsync(user, model.Password); if (result.Succeeded) { //TODO: SignIn return RedirectToAction("UserRegisterSuccessfully", model); } return View(model); }
private async Task SignInAsync(User user, bool isPersistent) { var authentication = HttpContext.GetOwinContext().Authentication; authentication.SignOut(DefaultAuthenticationTypes.ExternalCookie); var identity = await AppUserManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie); authentication.SignIn(new AuthenticationProperties {IsPersistent = isPersistent},identity); }