Example #1
0
        public async Task <DataResultDto <UserDto> > CheckUser(UserDto userDto)
        {
            DataResultDto <UserDto> dataResultDto = new DataResultDto <UserDto>();
            User   user = null;
            string sql  = "select UserId,LoginName,UserName,Password,Status,IsAdmin from `user` where LoginName=@LoginName and IsDelete=0 ";

            using (var connect = CreateConnection())
            {
                user = await connect.QueryFirstOrDefaultAsync <User>(sql, new { LoginName = userDto.LoginName });
            }
            if (user == null)
            {
                dataResultDto.Code = 1;
                dataResultDto.Msg  = "登陆失败,用户名不正确!";
            }
            else
            {
                if (user.Status == 0)
                {
                    string pwd  = $"{userDto.Password}{this._webStaticConfig.MD5Code}";
                    string spwd = SecurityTool.MD5Hash(pwd);
                    if (spwd.ToUpper() == user.Password.ToUpper())
                    {
                        UserDto quserDto = new UserDto();
                        quserDto               = Mapper.Map <User, UserDto>(user);
                        dataResultDto.Code     = 0;
                        dataResultDto.Msg      = "登陆成功!";
                        dataResultDto.DataList = quserDto;
                    }
                    else
                    {
                        dataResultDto.Code = 1;
                        dataResultDto.Msg  = "登陆失败,用户名或者密码不对!";
                    }
                }
                else if (user.Status == 1)
                {
                    dataResultDto.Code = 1;
                    dataResultDto.Msg  = "登陆失败,用户正在审核中!";
                }
                else if (user.Status == 2)
                {
                    dataResultDto.Code = 1;
                    dataResultDto.Msg  = "登陆失败,用户已冻结,请联系管理员!";
                }
                else if (user.Status == 3)
                {
                    dataResultDto.Code = 1;
                    dataResultDto.Msg  = "登陆失败,用户已禁用,请联系管理员!";
                }
                else
                {
                    dataResultDto.Code = 1;
                    dataResultDto.Msg  = "登陆失败,用户名或者密码错误!";
                }
            }

            return(dataResultDto);
        }
Example #2
0
        /// <summary>
        /// 添加用户
        /// </summary>
        /// <param name="userDto"></param>
        /// <returns></returns>
        public async Task <bool> AddUserAsync(UserDto userDto)
        {
            string pwd  = $"{userDto.Password}{this._webStaticConfig.MD5Code}";
            string spwd = SecurityTool.MD5Hash(pwd);

            userDto.Password       = spwd;
            userDto.UserHeadImaUrl = "/upload/user-head/default.jpg";
            string sql = "insert into `user`(LoginName,UserName,`Password`) VALUES(@LoginName,@UserName,@Password) ";

            using (var connect = CreateConnection())
            {
                return(await connect.ExecuteAsync(sql, new { LoginName = userDto.LoginName, UserName = userDto.UserName, Password = userDto.Password }) > 0);
            }
        }