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)); }
/// <summary> /// Creates the kernel that will manage your application. /// </summary> /// <returns>The created kernel.</returns> private static IKernel CreateKernel() { var kernel = new StandardKernel(); try { kernel.Bind <Func <IKernel> >().ToMethod(ctx => () => new Bootstrapper().Kernel); kernel.Bind <IHttpModule>().To <HttpApplicationInitializationHttpModule>(); RegisterServices(kernel); GlobalStoreHelper.Initialize(kernel.Get <IUserService>()); return(kernel); } catch { kernel.Dispose(); throw; } }