Пример #1
0
 public Result <SaveResponse> Register(RegisterRequest request)
 {
     request.CheckNotNull();
     return(new UserController().Create(new SaveRequest <UserRow>
     {
         Entity = new UserRow
         {
             Username = request.Username,
             Password = request.Password,
             Email = request.Email
         }
     }));
 }
Пример #2
0
        public async Task <BaseApiResponse> Register(RegisterRequest request)
        {
            request.CheckNotNull(nameof(request));
            //验证码验证
            if (request.Token.IsNullOrEmpty() || _apiSession.GetMsgCode(request.Token) == null)
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "验证码过期"
                });
            }
            if (_apiSession.GetMsgCode(request.Token) != request.MsgCode)
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "验证码错误"
                });
            }

            if (!request.Mobile.IsMobileNumber())
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "手机号不正确"
                });
            }
            if (request.Password.Length > 20)
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "密码长度不能大于20字符"
                });
            }
            if (request.Password.Contains(" "))
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "密码不能包含空格."
                });
            }

            //检查手机号是否可用
            if (!_userQueryService.CheckMobileIsAvliable(request.Mobile))
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "该手机号已注册."
                });
            }

            //创建用户command
            var userViewModel = new UserViewModel {
                Id       = GuidUtil.NewSequentialId(),
                ParentId = request.ParentId,
                Mobile   = request.Mobile,
                NickName = "用户" + StringGenerator.Generate(4),//创建随机昵称
                Password = request.Password,
                Portrait = "http://wftx-goods-img-details.oss-cn-shanghai.aliyuncs.com/default-userpic/userpic.png",
                Region   = "北京",
                Gender   = "保密"
            };
            var command = userViewModel.ToCreateUserCommand();
            var result  = await ExecuteCommandAsync(command);

            if (!result.IsSuccess())
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "命令没有执行成功:{0}".FormatWith(result.GetErrorMessage())
                });
            }

            return(new RegisterResponse
            {
                Result = new RegisterResult
                {
                    Id = command.AggregateRootId.ToString()
                }
            });
        }