예제 #1
0
        public async Task <VerificationEmailResponse> VerificationEmailAsync(VerificationEmailRequest request)
        {
            var response = new VerificationEmailResponse();
            var user     = await _users.FirstOrDefaultAsync(d => d.UserName == request.UserName);

            if (user == null)
            {
                return(response.ReturnWithCode(AuthenticationMessageHelper.Code.VerificationEmailFailedInvalidUser.Value(), AuthenticationMessageHelper.ResponseMessages));
            }
            if (user.UserStatus != UserStatus.WaitingConfirmationEmail)
            {
                return(response.ReturnWithCode(AuthenticationMessageHelper.Code.VerificationEmailFailedInvalidUserStatus.Value(), AuthenticationMessageHelper.ResponseMessages));
            }
            if (!user.EmailTokenLifespanDateTimeOn.HasValue || string.IsNullOrEmpty(user.EmailToken))
            {
                return(response.ReturnWithCode(AuthenticationMessageHelper.Code.VerificationEmailFailedInvalidTokenData.Value(), AuthenticationMessageHelper.ResponseMessages));
            }
            var decryptEmailToken = _stringEncryption.Decrypt(user.EmailToken);

            if (decryptEmailToken != request.VerificationEmailToken)
            {
                return(response.ReturnWithCode(AuthenticationMessageHelper.Code.VerificationEmailFailedInvalidTokenCode.Value(), AuthenticationMessageHelper.ResponseMessages));
            }
            if (user.EmailTokenLifespanDateTimeOn.Value <= DateTimeOffset.UtcNow.IranStandardTimeNow())
            {
                return(response.ReturnWithCode(AuthenticationMessageHelper.Code.VerificationEmailFailedExpiredTokenCode.Value(), AuthenticationMessageHelper.ResponseMessages));
            }
            user.UserStatus     = UserStatus.Active;
            user.EmailConfirmed = true;
            user.CleanEmailToken();
            await _unitOfWork.SaveChangesAsync();

            return(response.ReturnWithCode(AuthenticationMessageHelper.Code.VerificationEmailSuccess.Value(), AuthenticationMessageHelper.ResponseMessages));
        }
예제 #2
0
        public override async Task <VerificationEmailResponse> SendVerificationEmail(VerificationEmailRequest request, ServerCallContext context)
        {
            var result = new VerificationEmailResponse();

            var response = await _walletApiV1Client.SendVerificationEmailAsync(new PostEmailModel { Email = request.Email });

            if (response.Result != null)
            {
                result.Body = new VerificationEmailResponse.Types.Body {
                    Token = response.Result.Token
                };
            }

            if (response.Error != null)
            {
                result.Error = response.Error.ToApiError();
            }

            return(result);
        }