public JsonResult LogIn(LogInUserViewModel logInUserViewModel) { if (!ModelState.IsValid) { return(Json(new { success = false, message = Constants.ErrorMessage })); } var password = AuthorizationHelper.GetHashString(logInUserViewModel.Password); var user = _userService.CheckUserExists(logInUserViewModel.UserId, password); if (user == null) { return(Json(new { success = false, message = "Неправильный пароль!" })); } FormsAuthentication.SetAuthCookie(user.Name, logInUserViewModel.RememberMe); GlobalStoreHelper.SetSession(user); return(Json(new { success = true, nextPage = Url.Action("Index", "Home") }, JsonRequestBehavior.AllowGet)); }
protected override bool AuthorizeCore(HttpContextBase httpContext) { if (httpContext == null) { throw new ArgumentNullException("httpContext"); } if (httpContext.User == null || !httpContext.User.Identity.IsAuthenticated) { return(false); } if (httpContext.Session == null || !(httpContext.Session[Constants.SessionKeyUser] is User)) { GlobalStoreHelper.SetSession(httpContext.User.Identity.Name); } var user = httpContext.Session[Constants.SessionKeyUser] as User; return(user != null && RequiredUsers.Contains((UsersEnum)user.Id)); }