public async Task<ActionResult> Register([Bind(Include = "Email,Password,RepeatPassword")] RegisterModel model) { if (!ModelState.IsValid) { return View(); } var user = new AppUser { Email = model.Email, DateCreated = DateTime.Now, UserName = model.Email }; var result = await userManager.CreateAsync(user, model.Password); if (result.Succeeded) { await SignIn(user); return RedirectToAction("Index", "Notes"); } foreach (var error in result.Errors) { ModelState.AddModelError("Email", error); } return View(); }
private async Task SignIn(AppUser user) { var identity = await userManager.CreateIdentityAsync( user, DefaultAuthenticationTypes.ApplicationCookie); GetAuthenticationManager().SignIn(identity); }