Example #1
0
 public ActionResult Index(LoginViewModel login)
 {
     var user = Context.GetUser(login.Email, login.Password);
     if (user != null)
     {
         login.Role = SecurityHelper.GetRoleType(user.Role);
         login.Password = string.Empty;
         login.UserName = user.UserName;
         CacheHelper._CacheHelper.SetLoggedInUser(login);
         return RedirectToAction("Index", "Dashboard");
     }
     login.Password = string.Empty;
     login.ErrorMessage = "Sai email đăng nhập hay mật khẩu.";
     return View(login);
 }
Example #2
0
 public void SetLoggedInUser(LoginViewModel user)
 {
     var xmlDoc = new XmlDocument();
     var xmlFilePath = HttpContext.Current.Server.MapPath("~/Areas/BackendSite/Models");
     switch (user.Role)
     {
         case RoleType.Admin:
             xmlFilePath = Path.Combine(xmlFilePath, "UserAdminMenu.xml");
             break;
         case RoleType.Editor:
             xmlFilePath = Path.Combine(xmlFilePath, "UserEditorMenu.xml");
             break;
         case RoleType.Member:
             xmlFilePath = Path.Combine(xmlFilePath, "UserMemberMenu.xml");
             break;
         default:
             break;
     }
     xmlDoc.Load(xmlFilePath);
     var menu = new List<MenuLinkContainer>();
     foreach (XmlElement node in xmlDoc.DocumentElement.ChildNodes)
     {
         var item = new MenuLinkContainer();
         item.Menu = new MenuLink()
         {
             IsCurrent = node.GetAttribute("IsActive") == "true",
             Link = node.GetAttribute("Link"),
             LinkText = node.GetAttribute("MenuText")
         };
         if (node.HasChildNodes)
         {
             item.Links = node.ChildNodes.Cast<XmlElement>().Select(child => new MenuLink()
             {
                 IsCurrent = child.GetAttribute("IsActive") == "true",
                 LinkText = child.GetAttribute("MenuText"),
                 Link = child.GetAttribute("Link")
             }).ToList();
         }
         menu.Add(item);
     }
     user.UserMenu = menu;
     HttpContext.Current.Session[UserLoginSession] = user;
 }