Esempio n. 1
0
 public async Task <ApiResult> SignUpWithUserNamePasswordAsync([FromBody] UserNamePasswordSignUpRequest request)
 {
     //core层加一个模型验证错误响应
     if (!ModelState.IsValid)
     {
         return(InValidModelsError());
     }
     return(await _userService.SignUpWithUserNamePasswordAsync(request));
 }
Esempio n. 2
0
        /// <summary>
        /// 用户名密码注册
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public async Task <ApiResult> SignUpWithUserNamePasswordAsync(UserNamePasswordSignUpRequest request)
        {
            var response = new ApiResult();

            try
            {
                var isExist = await _userRepository.TableNotTracking
                              .AnyAsync(item => item.UserName == request.UserName);

                if (isExist)
                {
                    response.Code    = Code.Error;
                    response.Message = "该用户名已存在请重新输入";
                    return(response);
                }
                var user = new User(true)
                {
                    UserName   = request.UserName,
                    CreateTime = DateTime.Now,
                    Status     = 1
                };
                var userPassword = new UserPassword(true)
                {
                    UserId           = user.Id,
                    PasswordHash     = _userPasswordService.PasswordToHash(request.Password),
                    PasswordStrength = request.PasswordStrength,
                    Status           = 1,
                    CreateTime       = DateTime.Now
                };
                await _userRepository.InsertAsync(user);

                await _userPasswordRepository.InsertAsync(userPassword);

                await _work.SaveChangesAsync();

                response.Code    = Code.Ok;
                response.Message = "注册成功";
                return(response);
            }
            catch (Exception ex)
            {
                _logger.LogError($"注册异常;method={nameof(SignUpWithUserNamePasswordAsync)};param={request.ToJson()};exception messges={ex.Message}");
                response.Code    = Code.Error;
                response.Message = $"注册异常:{ex.Message}";
                return(response);
            }
        }