//Аутентификация пользователя public async Task<string> LoginAsync(LoginUserModel userLogin, IAuthenticationManager authenticationManager) { CatalogUser user = await _userManager.FindAsync(userLogin.UserName, userLogin.Password); if (user == null) { return "Неверный логин или пароль"; } else if (user.Activated == false) { return "Ваша учётная запись ещё не активирована администратором."; } else { ClaimsIdentity claim = await _userManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie); authenticationManager.SignOut(); authenticationManager.SignIn(new AuthenticationProperties { IsPersistent = userLogin.RememberMe, }, claim); return null; } }
public async Task<ActionResult> Login(LoginUserModel userLogin, string returnUrl) { if (ModelState.IsValid) { string result = await UserService.LoginAsync(userLogin, HttpContext.GetOwinContext().Authentication); if (!String.IsNullOrEmpty(result)) { ModelState.AddModelError("", result); } else { if (String.IsNullOrEmpty(returnUrl)) { return RedirectToAction("Index", "Home"); } return Redirect(returnUrl); } } return View(); }