u
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Blazored.LocalStorage;
|
||||
using Blazored.LocalStorage;
|
||||
using FrontOffice.BFF.User.Protobuf.Protos.User;
|
||||
using FrontOffice.BFF.User.Protobuf.Validator;
|
||||
using FrontOffice.Main.Utilities;
|
||||
@@ -19,10 +18,10 @@ public partial class Verify : IDisposable
|
||||
private const string RedirectStorageKey = "auth:redirect";
|
||||
private const string TokenStorageKey = "auth:token";
|
||||
|
||||
private static readonly VerifyOtpTokenRequestValidator VerifyRequestValidator = new();
|
||||
|
||||
private readonly OtpInputModel _model = new();
|
||||
private VerifyOtpTokenRequestValidator _requestValidator = new();
|
||||
private VerifyOtpTokenRequest _request = new();
|
||||
private MudForm? _form;
|
||||
|
||||
private bool _isBusy;
|
||||
private string? _phoneNumber;
|
||||
private string? _redirect;
|
||||
@@ -40,6 +39,7 @@ public partial class Verify : IDisposable
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
_request.Purpose = OtpPurpose;
|
||||
var uri = Navigation.ToAbsoluteUri(Navigation.Uri);
|
||||
var query = QueryHelpers.ParseQuery(uri.Query);
|
||||
if (query.TryGetValue("redirect", out var redirectValues))
|
||||
@@ -84,15 +84,11 @@ public partial class Verify : IDisposable
|
||||
_infoMessage = null;
|
||||
|
||||
if (_form is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
return;
|
||||
|
||||
await _form.Validate();
|
||||
if (!_form.IsValid)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (IsVerificationLocked)
|
||||
{
|
||||
@@ -112,14 +108,8 @@ public partial class Verify : IDisposable
|
||||
|
||||
try
|
||||
{
|
||||
var request = new VerifyOtpTokenRequest
|
||||
{
|
||||
Mobile = _phoneNumber,
|
||||
Purpose = OtpPurpose,
|
||||
Code = _model.Code
|
||||
};
|
||||
|
||||
var validationResult = VerifyRequestValidator.Validate(request);
|
||||
_request.Mobile = _phoneNumber;
|
||||
var validationResult = _requestValidator.Validate(_request);
|
||||
if (!validationResult.IsValid)
|
||||
{
|
||||
_errorMessage = string.Join(" ", validationResult.Errors.Select(e => e.ErrorMessage).Distinct());
|
||||
@@ -130,11 +120,11 @@ public partial class Verify : IDisposable
|
||||
VerifyOtpTokenResponse response;
|
||||
if (metadata is not null)
|
||||
{
|
||||
response = await UserClient.VerifyOtpTokenAsync(request, metadata, cancellationToken: cancellationToken);
|
||||
response = await UserClient.VerifyOtpTokenAsync(_request, metadata, cancellationToken: cancellationToken);
|
||||
}
|
||||
else
|
||||
{
|
||||
response = await UserClient.VerifyOtpTokenAsync(request, cancellationToken: cancellationToken);
|
||||
response = await UserClient.VerifyOtpTokenAsync(_request, cancellationToken: cancellationToken);
|
||||
}
|
||||
|
||||
if (response is null)
|
||||
@@ -158,7 +148,7 @@ public partial class Verify : IDisposable
|
||||
await LocalStorage.RemoveItemAsync(RedirectStorageKey);
|
||||
|
||||
_attemptsLeft = MaxVerificationAttempts;
|
||||
_model.Code = string.Empty;
|
||||
_request.Code = string.Empty;
|
||||
|
||||
var target = !string.IsNullOrWhiteSpace(_redirect) ? _redirect : RouteConstants.Main.MainPage;
|
||||
if (!string.IsNullOrWhiteSpace(target))
|
||||
@@ -274,7 +264,7 @@ public partial class Verify : IDisposable
|
||||
: response.Message;
|
||||
|
||||
_attemptsLeft = MaxVerificationAttempts;
|
||||
_model.Code = string.Empty;
|
||||
_request.Code = string.Empty;
|
||||
StartResendCountdown();
|
||||
}
|
||||
catch (RpcException rpcEx)
|
||||
@@ -392,11 +382,4 @@ public partial class Verify : IDisposable
|
||||
_resendTimer?.Dispose();
|
||||
_resendTimer = null;
|
||||
}
|
||||
|
||||
private sealed class OtpInputModel
|
||||
{
|
||||
[Required(ErrorMessage = "???? ???? ??? ???? ?????? ???.")]
|
||||
[RegularExpression(@"^\\d{5,6}$", ErrorMessage = "??? ???? ???? ? ?? ? ??? ????.")]
|
||||
public string Code { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user