Example #1
0
        public async Task SignUpSucceedAsync()
        {
            var testSignUpEmail = "*****@*****.**";
            await _userRepository.DeleteAsync(it => it.UserEmail == testSignUpEmail);

            var code = Guid.NewGuid().ToString().Split("-")[0].ToUpper();

            _memoryCache.Set(testSignUpEmail, code, TimeSpan.FromSeconds(10));
            var signUpPara = new UserService_SignUpPara()
            {
                UserEmail            = testSignUpEmail,
                UserPassword         = "******",
                UserConfirmPassword  = "******",
                UserNickname         = "Test",
                UserVerificationCode = code
            };
            var result = await _userServiceController.SignUpAsync(signUpPara);

            var resultObj = result.Result as OkObjectResult;
            var resultVal = resultObj.Value as UserService_SignUpDto;

            Assert.InRange((int)resultObj.StatusCode, 200, 299);
            Assert.True(resultVal.IsSuccess);
            _output.WriteLine(JsonSerializer.Serialize(resultVal, _options));
            await _userRepository.DeleteAsync(it => it.UserEmail == testSignUpEmail);
        }
Example #2
0
        public async Task <bool> SignUp(UserService_SignUpPara userService_SignUpPara)
        {
            if (userService_SignUpPara.UserVerificationCode != _memoryCache.Get(userService_SignUpPara.UserEmail)?.ToString())//判断验证码是否有效
            {
                return(false);
            }
            var willInsert = _mapper.Map <User>(userService_SignUpPara);
            await _userRepository.InsertAsync(willInsert);

            return(true);
        }
Example #3
0
 public async Task <ActionResult <UserService_SignUpDto> > SignUpAsync([FromBody] UserService_SignUpPara userService_SignUpPara)
 {
     if (await _userService.IsExist(_mapper.Map <UserService_IsExistPara>(userService_SignUpPara)))
     {
         return(Ok(new UserService_SignUpDto()
         {
             IsSuccess = false, Message = "该邮箱已经被注册!"
         }));
     }
     if (!await _userService.SignUp(userService_SignUpPara))
     {
         return(Ok(new UserService_SignUpDto()
         {
             IsSuccess = false, Message = "验证码错误或已失效!"
         }));
     }
     else
     {
         return(Ok(new UserService_SignUpDto()
         {
             IsSuccess = true, Message = "注册成功!"
         }));
     }
 }