Пример #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);
        }
Пример #2
0
        public AjaxResult Login(Login login, HttpContextBase httpContext)
        {
            AjaxResult result = new AjaxResult();

            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);
                //供应商赋值
                //var supplier = supplierBll.GetSupplierByOperatorId(user.SysOperator.ID);
                //if (supplier != null)
                //{
                //    user.Supplier = supplier;
                //}
                if ((user.SysCorp.Status != 0))
                {
                    result.flag    = false;
                    result.message = "公司状态异常,请联系管理员!";
                    return(result);
                }
                else if (user.SysOperator.Status != 0)
                {
                    result.flag    = false;
                    result.message = "操作员状态异常,请联系管理员!";
                    return(result);
                }
                else
                {
                    user.Privileges = sysOperatorService.GetPrivilege(operators[0].ID);
                    menus           = sysOperatorService.GetMenu(operators[0].ID);
                    if (menus.Count > 0)
                    {
                        user.Menus = (from menu in menus where menu.Parent == 0 && 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);
                    //添加登录日志
                    sysLoginLogDal.Add(new SysLoginLog()
                    {
                        Ip         = Common.Common.GetHostAddress(),
                        LoginAgent = System.Web.HttpContext.Current.Request.Browser.Version.ToString(),
                        Operator   = user.SysOperator.ID,
                        Success    = true,
                        Time       = DateTime.Now
                    });
                    result.flag = true;
                }
            }
            else
            {
                result.flag    = false;
                result.message = "用户名或密码错误";
                return(result);
            }
            return(result);
        }