Ejemplo n.º 1
0
        public void Login(string userName, string password)
        {
            var user = _userService.GetUserByUserName(userName);
            if (user == null || user.UserStatus == EnumUserStatus.Deleted)
            {
                throw new NullReferenceException("不存在用户!");
            }

            if (user.UserStatus == EnumUserStatus.Forbid)
            {
                throw new NullReferenceException("当前用户已经被禁止登录!");
            }

            if (user.Password != password.GetMD5By32())
            {
                throw new NullReferenceException("用户名或密码不正确!");
            }
            

            var passport = new EPassport();
            passport.User = user;
            passport.Roles = _userService.GetVUserRolesByUserId(user.Id);
            if (user.IsSuperAdmin)
            {
                passport.Menu = _menuService.GetMenuTree();
            }
            else
            {
                passport.Auths = _menuService.GetAllMenuAuthsByUserId(user.Id);
                passport.Menu = _menuService.GetMenuTreeByUserId(user.Id, passport.Auths);
            }

            //更新用户信息
            _rep.Save(new EUser() { LastLoginTime = DateTime.Now }, p => p.Id == user.Id, p => new Columns(p.LastLoginTime));

            _stateService.SavePassport(passport);
        }
Ejemplo n.º 2
0
        public EPassport LoginByApp(string userName, string password, bool isPasswordMd5 = false)
        {

            var user = _userService.GetUserByUserName(userName);
            if (user == null)
            {
                throw new NullReferenceException("不存在用户!");
            }

            if (user.UserStatus == EnumUserStatus.Forbid)
            {
                throw new NullReferenceException("当前用户已经被禁止登录!");
            }
            if (isPasswordMd5)
            {
                if (user.Password != password)
                {
                    throw new NullReferenceException("用户名或密码不正确!");
                }
            }
            else
            {
                if (!user.Password.Equals(password.GetMD5By32(),StringComparison.CurrentCultureIgnoreCase))
                {
                    throw new NullReferenceException("用户名或密码不正确!");
                }
            }
            user.AppTicket = Guid.NewGuid().ToString();
            _rep.Save(user, p => p.Id == user.Id, p => new Columns(p.AppTicket));

            var passport = new EPassport();
            passport.User = user;
            passport.Roles = _userService.GetVUserRolesByUserId(user.Id);
            return passport;
        }
Ejemplo n.º 3
0
        private void LoginByOpenLogin(EUser user)
        {
            if (user == null)
            {
                throw new NullReferenceException("不存在用户!");
            }

            if (user.UserStatus == EnumUserStatus.Forbid)
            {
                throw new NullReferenceException("当前用户已经被禁止登录!");
            }

            var passport = new EPassport();
            passport.User = user;
            passport.Roles = _userService.GetVUserRolesByUserId(user.Id);
            if (user.IsSuperAdmin)
            {
                passport.Menu = _menuService.GetMenuTree();
            }
            else
            {
                passport.Auths = _menuService.GetAllMenuAuthsByUserId(user.Id);
                passport.Menu = _menuService.GetMenuTreeByUserId(user.Id, passport.Auths);
            }

            //更新用户信息
            _rep.Save(new EUser() { LastLoginTime = DateTime.Now }, p => p.Id == user.Id, p => new Columns(p.LastLoginTime));

            _stateService.SavePassport(passport);
        }
Ejemplo n.º 4
0
 public void SavePassport(EPassport passport)
 {
     HttpContext.Current.Session["Passport"] = passport;
 }