public async Task <ApiResult> BindMobile(MobileValidationCodeLoginInput input)
        {
            var returnResult = new ApiResult();
            var verifyMobileValidationCodeInput = new VerifyMobileValidationCodeInput
            {
                Mobile         = input.Mobile,
                Type           = MobileValidationCodeType.Bind, // 绑定
                ValidationCode = input.ValidationCode,
            };

            if (!await _mobileUserService.VerifyMobileValidationCodeAsync(verifyMobileValidationCodeInput, ModelState))
            {
                returnResult.Code    = 400;
                returnResult.Message = ModelState.FirstErrorMessage();
                return(returnResult);
            }
            var bindResult = await _mobileUserService.ChangeMobileAsync(HttpContext.User.GetUserId(),
                                                                        input.Mobile,
                                                                        true,
                                                                        ModelState);

            if (!bindResult)
            {
                returnResult.Code    = 400;
                returnResult.Message = ModelState.FirstErrorMessage();
                return(returnResult);
            }

            returnResult.Code    = 200;
            returnResult.Message = "绑定成功";
            return(returnResult);
        }
示例#2
0
        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);
        }
示例#3
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);
        }