public async Task <ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { var user = new MoviesLabUser() { UserName = model.UserName, Name = model.Name, Surname = model.Surname }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { await SignInAsync(user, isPersistent : false); UserManager.AddToRole(user.Id, "Пользователь"); return(RedirectToAction("Index", "Home")); } else { AddErrors(result); } } // Появление этого сообщения означает наличие ошибки; повторное отображение формы return(View(model)); }
private async Task SignInAsync(MoviesLabUser user, bool isPersistent) { AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie); var identity = await UserManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie); AuthenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = isPersistent }, identity); }
public ActionResult Favorites() { MoviesLabUser user = db.Users.Find(User.Identity.GetUserId()); List <Person> favPerson = new List <Person>(); if (user.FavMovie != null) { favPerson = user.FavPerson.Where(fp => fp.Delete = false).ToList(); } return(View(favPerson)); }
public ActionResult Favorites() { MoviesLabUser user = db.Users.Find(User.Identity.GetUserId()); List <Movie> favMovie = new List <Movie>(); if (user.FavMovie != null) { favMovie = user.FavMovie.Where(fm => fm.Delete = false).ToList(); } return(View(favMovie)); }