public async Task <ApiTokenResult> MobileLogin(MobileValidationCodeLoginInput input)
        {
            var returnResult = new ApiTokenResult();
            var verifyMobileValidationCodeInput = new VerifyMobileValidationCodeInput
            {
                Mobile         = input.Mobile,
                Type           = MobileValidationCodeType.Login, // 登录
                ValidationCode = input.ValidationCode,
            };

            if (!await _mobileUserService.VerifyMobileValidationCodeAsync(verifyMobileValidationCodeInput, ModelState))
            {
                returnResult.Code    = 400;
                returnResult.Message = ModelState.FirstErrorMessage();
                return(returnResult);
            }
            var userInfo = await _mobileUserService.GetOrGenerateItemByMobileAsync(_authenticationSettings.RegisterDefaultGroupId,
                                                                                   _authenticationSettings.RegisterDefaultStatus,
                                                                                   input.Mobile,
                                                                                   true,
                                                                                   ModelState);

            if (userInfo == null)
            {
                returnResult.Code    = 400;
                returnResult.Message = ModelState.FirstErrorMessage();
                return(returnResult);
            }

            if (userInfo.Status != UserStatus.Normal)
            {
                returnResult.Code    = 201;
                returnResult.Message = "注册成功,请等待审核。";
                return(returnResult);
            }

            var token        = _tokenService.GenerateAccessToken(userInfo);
            var refreshToken = await _tokenService.GenerateRefreshToken(userInfo.UserId);

            returnResult.Token        = token;
            returnResult.RefreshToken = refreshToken;
            returnResult.Code         = 200;
            returnResult.Message      = "登录成功";
            return(returnResult);
        }
Example #2
0
        public async Task <ApiResultData <ApiResultTokenData> > MobileLogin(MobileValidationCodeLoginInput input)
        {
            var returnResult = new ApiResultData <ApiResultTokenData>();
            var verifyMobileValidationCodeInput = new VerifyMobileValidationCodeInput
            {
                Mobile         = input.Mobile,
                Type           = MobileValidationCodeType.Login, // 登录
                ValidationCode = input.ValidationCode,
            };

            if (!await _mobileUserService.VerifyMobileValidationCodeAsync(verifyMobileValidationCodeInput, ModelState))
            {
                returnResult.Code    = 400;
                returnResult.Message = ModelState.FirstErrorMessage();
                return(returnResult);
            }
            var userInfo = await _mobileUserService.GetOrGenerateItemByMobileAsync(_authenticationSettings.RegisterDefaultGroupId,
                                                                                   _authenticationSettings.RegisterDefaultStatus,
                                                                                   input.Mobile,
                                                                                   true,
                                                                                   ModelState);

            if (userInfo == null)
            {
                returnResult.Code    = 400;
                returnResult.Message = ModelState.FirstErrorMessage();
                return(returnResult);
            }

            if (userInfo.Status != UserStatus.Normal)
            {
                returnResult.Code    = 201;
                returnResult.Message = "注册成功,请等待审核。";
                return(returnResult);
            }

            await SaveUserActionLogAsync(userInfo.UserId, 1, "手机号 + 验证码 登录", input);

            returnResult.Data = await _tokenService.GenerateApiResultTokenData(userInfo);

            returnResult.Code    = 200;
            returnResult.Message = "登录成功";
            return(returnResult);
        }