Exemplo n.º 1
0
        public bool Login(Login login, HttpContextBase httpContext)
        {
            List<SysOperator> operators;
            List<SysMenu> menus;
            operators = sysOperatorService.Login(login.Name, Util.GetPassword(login.Name, login.Password), httpContext.Session.SessionID, HttpUtil.GetClientIP(httpContext));

            if (operators.Count > 0)
            {
                User user = new User();
                user.SysOperator = operators[0];
                user.SysCorp = sysOperatorService.GetCorp(user.SysOperator.Corp);
                user.Privileges = sysOperatorService.GetPrivilege(operators[0].ID);
                menus = sysOperatorService.GetMenu(operators[0].ID);
                if (menus.Count > 0)
                {
                    SysMenu root = (from menu in menus where menu.ID == menu.Parent select menu).FirstOrDefault();
                    if (root != null)
                    {
                        user.Menus = (from menu in menus where menu.Parent == root.ID && menu.ID != menu.Parent select new UserMenu(menu, new List<UserMenu>())).ToList();
                        foreach (UserMenu userMenu in user.Menus)
                        {
                            userMenu.Children = (from menu in menus where menu.Parent == userMenu.SysMenu.ID && menu.ID != menu.Parent select new UserMenu(menu, new List<UserMenu>())).ToList();
                        }
                    }
                }
                if (null == user.Menus)
                {
                    user.Menus = new List<UserMenu>();
                }
                httpContext.Session.Add(Constants.USER_KEY, user);
            }
            return operators.Count > 0;
        }
Exemplo n.º 2
0
 public ActionResult Login()
 {
     Session.Abandon();
     Login login = new Login();
     login.Name = "admin";
     login.Password = "******";
     return View();
 }
Exemplo n.º 3
0
 public ActionResult Login(Login login)
 {
     if (ModelState.IsValid)
     {
         if (!login.Captcha.Equals(HttpContext.Session[Constants.CAPTCHA]))
         {
             ModelState.AddModelError("Captcha", "验证码输入错误");
             return View("Login", login);
         }
         if (SysOperatorBll.Login(login, HttpContext))
         {
             return RedirectToAction("Index", "Home");
         }
         else
         {
             ModelState.AddModelError("Name", "用户名或密码错误");
             ModelState.AddModelError("Password", "密码或用户名错误");
             return View("Login", login);
         }
     }
     return View("Login", login);
 }