public static string GetUserRole(this HtmlHelper html) { string CurrentUserEmail = HttpContext.Current.User.Identity.Name.ToString(); string CurrentUserRole = SqlUser.GetUserRole(CurrentUserEmail); return(CurrentUserRole); }
public ActionResult Login(UserLogin login, string ReturnUrl = "") { bool Status = false; string message = ""; if (SqlUser.CheckUserExists(login.Email)) { if (!SqlUser.CheckEmailVeryfied(login)) { ViewBag.Message = Resources.Texts.VerifyYourEmail; return View(); } if (string.Compare(Crypto.Hash(login.Password), SqlUser.GetUserPassword(login)) == 0) { int timeout = login.RememberMe ? 525600 : 30; // 525600 min = 1 rok, 30 dni czas zycia cookiem var ticket = new FormsAuthenticationTicket(login.Email, login.RememberMe, timeout); string encrypted = FormsAuthentication.Encrypt(ticket); var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encrypted) { Expires = DateTime.Now.AddMinutes(timeout), HttpOnly = true }; Response.Cookies.Add(cookie); Status = true; if (Url.IsLocalUrl(ReturnUrl)) { return Redirect(ReturnUrl); } else { switch (SqlUser.GetUserRole(login.Email)) { case "administrator": return RedirectToAction("Index", "Admin"); //case "worker": //return RedirectToAction("Profile", "User"); case "user": return RedirectToAction("Profile", "User"); } } } else { message = Resources.Texts.InvalidPassword; } } else { message = Resources.Texts.InvalidUser; } ViewBag.Message = message; ViewBag.Status = Status; return View(); }