public static bool IsAuthenticated(HttpContextBase httpContext) { var authCookie = httpContext.Request.Cookies["__AUTH"]; if (authCookie != null) { User user = ServiceToWorkWithUsers.GetUserByCookeis(authCookie.Value); return(user != null); } return(false); }
public static User GetUser(HttpContextBase httpContext) { var authCookie = httpContext.Request.Cookies["__AUTH"]; if (authCookie != null) { User user = ServiceToWorkWithUsers.GetUserByCookeis(authCookie.Value); return(user); } return(null); }
protected override bool AuthorizeCore(HttpContextBase httpContext) { var authCooke = httpContext.Request.Cookies["__AUTH"]; if (authCooke != null) { User user = ServiceToWorkWithUsers.GetUserByCookeis(authCooke.Value); if (user != null) { return(UserRoles.Split(',').Any(r => r.Trim().ToLower() == user.Role.RoleName.Trim().ToLower())); } return(false); } return(false); }
private ActionResult LoginAfterRegistration(AutorizeModel autorize) { User user = ServiceToWorkWithUsers.GetUser(autorize.LastName, autorize.Password); if (user != null) { Helpers.AuthHelper.LogInUser(HttpContext, user.Cookies); switch (user.Role.RoleName) { case "Admin": return(RedirectToAction("Admin", "Admin")); case "User": return(RedirectToAction("Index", "Home")); } } return(RedirectToAction("Login", "Account")); }
public ActionResult Registration(User user) { if (!Helpers.AuthHelper.IsAuthenticated(HttpContext)) { user.RoleId = 2; user.Cookies = Guid.NewGuid().ToString(); // cookie для авторизации user.Password = Helpers.SecurityHelper.Hash(user.Password); if (!ServiceToWorkWithUsers.FindUser(user.LastName)) { return(RedirectToAction("Registration", "Account")); } ServiceToWorkWithUsers.AddUser(user); AutorizeModel autorize = new AutorizeModel() { LastName = user.LastName, Password = user.Password }; LoginAfterRegistration(autorize); } return(RedirectToAction("Login", "Account")); }