public ActionResult Login(LoginModel model, string returnUrl) { if (ModelState.IsValid) { TB_UserProfile userProfile = userRepository.login(model.UserName, model.Password); //userProfile.TB_User = new TB_User(); //userProfile.TB_User.Active = "true"; //userProfile.TB_Role = new TB_Role(); //userProfile.TB_Role.Role = "admin"; // HttpCookie roleCookie = new HttpCookie("roleCookie"); if (userProfile != null && userProfile.TB_User.Active == "true") { FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe); Session["UserSession"] = userProfile; //roleCookie["userRole"] = "admin"; //Response.AppendCookie(roleCookie); return(RedirectToAction("Index", "Home")); } else if (userProfile != null && userProfile.TB_User.Active == "false") { ModelState.AddModelError("", "User is not active."); return(View(model)); } } // If we got this far, something failed, redisplay form ModelState.AddModelError("", "The user name or password provided is incorrect."); return(View(model)); }
public static MvcHtmlString AdminHRMenu(this HtmlHelper helper) { HttpContext context = HttpContext.Current; TB_UserProfile role = (TB_UserProfile)context.Session["UserSession"]; StringBuilder navigationBuilder = new StringBuilder(); if (role.TB_Role.Role == "Admin") { navigationBuilder.Append("<li id=\"Worker\" class=\"i_32_inbox\"><a href=\"\\Home\\GetUsers\" title=\"Manage Worker\"><span class=\"tab_label\">Worker</span></a></li>"); } return(new MvcHtmlString(navigationBuilder.ToString())); }
protected override bool AuthorizeCore(HttpContextBase httpContext) { bool authorize = false; HttpContext context = HttpContext.Current; TB_UserProfile role = (TB_UserProfile)context.Session["UserSession"]; if (role == null) { return(authorize); } if (this.allowedroles.Contains(role.TB_Role.Role)) { authorize = true; } return(authorize); }
public static MvcHtmlString NavigationMenu(this HtmlHelper helper) { HttpContext context = HttpContext.Current; TB_UserProfile role = (TB_UserProfile)context.Session["UserSession"]; StringBuilder navigationBuilder = new StringBuilder(); navigationBuilder.Append("<aside class=\"sidebar\">"); navigationBuilder.Append("<ul class=\"tab_nav\">"); navigationBuilder.Append("<li class=\"active_tab i_32_dashboard\">"); navigationBuilder.Append("<a href=\"index.html\" title=\"General Info\">"); navigationBuilder.Append("<span class=\"tab_label\">Dashboard</span>"); navigationBuilder.Append("<span class=\"tab_info\">General Info</span></a></li><li class=\"i_32_inbox\"><a href=\"inbox.html\" title=\"Your Messages\"><span class=\"tab_label\">Inbox</span><span class=\"tab_info\">Your Messages</span></a></li>"); if (role.TB_Role.Role == "admin") { navigationBuilder.Append("<li class=\"i_32_charts\"><a href=\"charts.html\" title=\"Visual Data\"><span class=\"tab_label\">Charts</span><span class=\"tab_info\">Visual Data</span></a></li>"); navigationBuilder.Append("<li class=\"i_32_ui\"><a href=\"ui.html\" title=\"Kit elements\"><span class=\"tab_label\">UI</span><span class=\"tab_info\">Kit elements</span></a></li>"); navigationBuilder.Append("<li class=\"i_32_tables\"><a href=\"tables.html\" title=\"Some Rows\"><span class=\"tab_label\">Tables</span><span class=\"tab_info\">Some Rows</span></a></li>"); navigationBuilder.Append("<li class=\"i_32_forms\"><a href=\"forms.html\" title=\"Some Fields\"><span class=\"tab_label\">Forms</span><span class=\"tab_info\">Some Fields</span></a></li>"); } navigationBuilder.Append("</ul></aside>"); return(new MvcHtmlString(navigationBuilder.ToString())); }