Files
Hushian/Presentation/HushianWebApp/Components/Verification.razor

188 lines
6.3 KiB
Plaintext
Raw Normal View History

2025-10-03 23:30:50 +03:30
@using Common.Dtos.Verification
2025-07-11 20:37:28 +03:30
@using Common.Enums
@using HushianWebApp.Service
@inject VerificationService verificationService;
@inject NavigationManager navigation;
<div class="header-form">
2025-07-24 23:18:11 +03:30
<span style="font-size: small;white-space: pre-line;">@Title</span>
2025-07-11 20:37:28 +03:30
</div>
@if (type == VerificationCodeType.ForgetPassword)
{
2025-10-03 23:30:50 +03:30
<div style="justify-content: space-between;margin-top:5px;margin-bottom:15px">
<input class="cus-input" maxlength='4' @bind-value="code" @bind-value:event="oninput" />
</div>
2025-07-24 23:18:11 +03:30
<div style="justify-content: space-between">
2025-07-11 20:37:28 +03:30
<TextInput @bind-value=Value type="password" name="Value" style="text-align:center;margin-top: 10px;;margin-left: 10px" placeholder="کلمه عبور جدید" required="required" />
<TextInput @bind-value=ReValue type="password" name="ReValue" style="text-align:center;margin-top: 10px;;margin-left: 10px" placeholder="تکرار کلمه عبور جدید" required="required" />
<Button Loading=loading LoadingText="ارسال درخواست" @onclick=onClick Color="ButtonColor.Success" style="margin-top: 10px;;margin-left: 10px"> احراز </Button>
</div>
}
else
{
2025-07-24 23:18:11 +03:30
<div style="justify-content: space-between;margin-top:5px">
2025-10-03 23:30:50 +03:30
<input class="cus-input" maxlength='4' @bind-value="code" @bind-value:event="oninput" />
2025-07-11 20:37:28 +03:30
</div>
}
<div style="display: flex; justify-content: space-between">
<Button Disabled=Disabledresendmsg @onclick=onClickresend Color="ButtonColor.Link" style="font-size: small;font-weight: normal;text-decoration: none;"> @resendmsg </Button>
</div>
@code {
[Parameter]
// PhoneNumberConfirmed
public VerificationCodeType type { get; set; }
[Parameter]
public string sendValue { get; set; }
[Parameter]
public int? ID { get; set; }
2025-10-03 23:30:50 +03:30
private string? _code = string.Empty;
public string? code
{
get { return _code; }
set
{
_code = value;
if (value.Length == 4)
onClick().ConfigureAwait(true);
}
}
2025-07-11 20:37:28 +03:30
[Parameter] public string? Title { get; set; }
[Inject] protected ToastService ToastService { get; set; } = default!;
[Parameter] public EventCallback<VerificationCodeType> OnMultipleOfThree { get; set; }
public string? Value { get; set; }
public string? ReValue { get; set; }
bool loading = false;
string resendmsg = "ارسال مجدد";
bool Disabledresendmsg = false;
2025-07-24 23:18:11 +03:30
//-----------------
2025-10-03 23:30:50 +03:30
//private string code1, code2, code3, code4;
2025-07-24 23:18:11 +03:30
private ElementReference input1, input2, input3, input4;
2025-07-11 20:37:28 +03:30
}
@functions {
protected override async Task OnParametersSetAsync()
{
resendmsg = "در حال ارسال کد احراز ...";
Disabledresendmsg = true;
if (ID == 0)
ID = await verificationService.FromUserName(sendValue, type);
ToastService.Notify(new(ToastType.Info, $"کد احراز به کاربری '{sendValue}' ارسال شد"));
resendmsg = "ارسال مجدد";
Disabledresendmsg = false;
await base.OnParametersSetAsync();
}
async Task onClickresend()
{
resendmsg = "در حال ارسال مجدد کد احراز ...";
Disabledresendmsg = true;
if (ID == 0)
ID = await verificationService.FromUserName(sendValue, type);
else
{
await verificationService.ReSendCode(ID.Value);
}
ToastService.Notify(new(ToastType.Info, $"کد احراز به کاربری '{sendValue}' ارسال شد"));
resendmsg = "ارسال مجدد";
Disabledresendmsg = false;
}
async Task onClick()
{
if (string.IsNullOrEmpty(code))
{
ToastService.Notify(new(ToastType.Warning, $"کد ارسالی را وارد کنید"));
return;
}
if (type == VerificationCodeType.ForgetPassword)
{
if (string.IsNullOrEmpty(Value) || string.IsNullOrEmpty(ReValue))
{
ToastService.Notify(new(ToastType.Warning, $"کلمه عبور جدید را مشخص کنید"));
return;
}
else
{
if (Value != ReValue)
2025-10-03 23:30:50 +03:30
{
ToastService.Notify(new(ToastType.Warning, $"کلمه عبور جدید و تکرار متفاوت هستند"));
return;
}
2025-07-11 20:37:28 +03:30
}
}
2025-10-03 23:30:50 +03:30
loading = true;
2025-07-11 20:37:28 +03:30
if (await verificationService.ConfirmedCode(new ConfirmedCodeDto()
{ code = code, codeType = type, Id = ID.Value, value = Value }))
{
ToastService.Notify(new(ToastType.Success, $"احراز با موفقیت انجام شد برای ادامه ورود کنید"));
await OnMultipleOfThree.InvokeAsync(type);
}
loading = false;
}
2025-10-03 23:30:50 +03:30
// private async Task MoveNext(ChangeEventArgs e)
// {
// if (e.Value?.ToString()?.Length == 1)
// {
// if (input1.Context == null) return;
// if (string.IsNullOrEmpty(code1))
// await input2.FocusAsync();
// else if (string.IsNullOrEmpty(code2))
// await input3.FocusAsync();
// else if (string.IsNullOrEmpty(code3))
// await input4.FocusAsync();
// else if (string.IsNullOrEmpty(code4))
// {
// code = $"{code1}{code2}{code3}{code4}";
// }
// }
// }
// private async Task OnLastInput(ChangeEventArgs e)
// {
// ///code4 = e.Value?.ToString();
// if (!string.IsNullOrEmpty(code) && code.Length == 4)
// {
// // code = $"{code1}{code2}{code3}{code4}";
// if (type == VerificationCodeType.PhoneNumberConfirmed)
// await onClick();
// }
// }
2025-07-24 23:18:11 +03:30
2025-10-03 23:30:50 +03:30
}
<style>
.cus-input {
direction: ltr;
display: block;
margin: 2em auto;
border: none;
padding: 0;
width: 6ch;
background: repeating-linear-gradient(90deg, dimgrey 0, dimgrey 1ch, transparent 0, transparent 1.5ch) 0 100%/ 5.5ch 2px no-repeat;
font: 5ch droid sans mono, consolas, monospace;
letter-spacing: 0.5ch;
2025-07-24 23:18:11 +03:30
}
2025-10-03 23:30:50 +03:30
input:focus {
outline: none;
color: dodgerblue;
}
2025-07-11 20:37:28 +03:30
2025-10-03 23:30:50 +03:30
</style>