Example #1
0
        public JsonResult SavePwd(DuPont.Models.UpdateUserInfo updateuserinfo, Int64 Id)
        {
            using (var result = new ResponseResult <UpdateUserInfo>())
            {
                //获取用户信息
                var user = _adminUserService.GetAll(m => m.UserName == updateuserinfo.PhoneNumber);
                if (user == null || user.Count() == 0)
                {
                    result.IsSuccess = false;
                    result.Message   = "用户不存在!";
                    return(Json(result));
                }

                var adminUser = user.ElementAt(0);
                updateuserinfo.OldPwd = Encrypt.MD5Encrypt(updateuserinfo.OldPwd);

                //校验输入密码与原密码是否一致
                if (adminUser.Password != updateuserinfo.OldPwd)
                {
                    result.IsSuccess = false;
                    result.Message   = "输入的密码与原密码不一致!";
                }
                //密码复杂度校验
                else if (!PageValidate.IsSafePassword(updateuserinfo.NewPwd))
                {
                    result.IsSuccess = false;
                    result.Message   = "密码必须包含字母、数字、特殊符号,且字母包含大小写长度在(7-18)";
                }
                else
                {
                    adminUser.Password = Encrypt.MD5Encrypt(updateuserinfo.NewPwd);
                    var isSuccess = _adminUserService.Update(adminUser) > 0;
                    if (isSuccess)
                    {
                        result.Message = "密码修改成功!";
                    }
                }
                return(new JsonResultEx(result));
            }
        }
Example #2
0
        public JsonResult Menu(Int64 userId)
        {
            using (ResponseResult <List <T_MENU> > result = new ResponseResult <List <T_MENU> >())
            {
                //获取用户信息
                var currentUser = userRepository.GetAll(user => user.Id == userId).FirstOrDefault();
                if (currentUser == null)
                {
                    throw new CustomException("用户不存在!");
                }

                IEnumerable <T_USER_ROLE_RELATION> user_RoleList = null;
                //非超级管理员,则获取用户拥有的角色信息
                if (!currentUser.IsSuperAdmin)
                {
                    //检查账号是否锁定
                    if (currentUser.IsLock)
                    {
                        throw new CustomException("用户已被锁定,禁止登录!");
                    }
                    user_RoleList = userRoleRepository.GetAll(userRole => userRole.UserID == userId && !userRole.MemberType);
                }

                if (currentUser.IsSuperAdmin || user_RoleList != null)
                {
                    IList <T_MENU> menuList = null;
                    if (currentUser.IsSuperAdmin)
                    {
                        menuList = menuRepository.GetAll(mnu => mnu.Visible);
                    }
                    else
                    {
                        var roleIdList    = user_RoleList.Select(userRole => userRole.RoleID).ToList <int>();
                        var role_MenuList = this.menuRoleRepository.GetAll(menuRole => roleIdList.Contains(menuRole.RoleId));
                        var menuIdList    = role_MenuList.Select(menuRole => menuRole.MenuId).ToList <int>();
                        menuList = this.menuRepository.GetAll(menu => menuIdList.Contains(menu.Id) && menu.Visible);
                    }

                    result.IsSuccess = true;
                    result.Entity    = menuList.ToList().OrderBy(mnu => mnu.Order).ToList();
                }
                else
                {
                    result.IsSuccess = false;
                    result.Message   = ResponeString.UserNotExist;
                }

                return(new JsonResultEx(result));
            }
        }
Example #3
0
        public AdminUserLoginInfo Authenticate(LoginInputDto input)
        {
            if (string.IsNullOrEmpty(input.LoginUserName))
            {
                throw new ArgumentNullException("LoginUserName");
            }

            if (string.IsNullOrEmpty(input.Password))
            {
                throw new ArgumentNullException("Password");
            }

            //根据账号和密码取得用户信息
            var adminUserInfo = adminUserRepository.GetAll(u => u.UserName == input.LoginUserName).FirstOrDefault();

            /*检查用户登录
             * --是户名是否存在
             * --密码是否匹配
             * --用户是否被锁定
             */
            CheckLoginCondition(adminUserInfo, input);

            //获取用户拥有的角色列表
            var userRoleList = adminUserRepository.GetRoles(adminUserInfo.Id);

            if (!adminUserInfo.IsSuperAdmin && userRoleList.Count() == 0)
            {
                throw new UnauthorizedAccessException();
            }

            var adminUserLoginInfo = new AdminUserLoginInfo()
            {
                Roles = userRoleList,
                User  = adminUserInfo
            };

            return(adminUserLoginInfo);
        }