This commit is contained in:
mmrbnjd
2025-07-31 19:05:58 +03:30
parent 38031b2e81
commit 23c4bc2800
3 changed files with 112 additions and 64 deletions

View File

@@ -38,7 +38,19 @@ namespace Common.Validation
public static bool CheckUsername(this string Username)
=> (Username.Length == 11 && Username.StartsWith("09"))
|| (Username.Length == 9 && Username.StartsWith("E/"));
public static bool CheckMobile(this string Mobile) => Mobile.Length == 11 && Mobile.StartsWith("09");
public static bool CheckMobile(this string Mobile)
{
bool pars = true;
foreach (var item in Mobile.ToCharArray())
{
if(!Int32.TryParse(item.ToString(),out int _))
{
pars = false;
break;
}
}
return pars && Mobile.Length == 11 && Mobile.StartsWith("09");
}
public static bool IsValidEmail(this string email)
{
// الگوی ساده اما معتبر برای بررسی ایمیل

View File

@@ -1,62 +1,74 @@
@using HushianWebApp.Service
@using Common.Validation
@using HushianWebApp.Service
@inject AuthService AuthService
@inject VerificationService verificationService;
<div class="login-form">
<div class="text-center mb-4">
<span class="badge bg-info p-2 rounded-pill">نیاز برای ارتباط با کارشناسان وارد شود</span>
</div>
<div class="form-container">
<Spinner Class="me-3" Type="SpinnerType.Dots" Color="SpinnerColor.Primary" Visible="@visible" />
<Spinner Class="me-3" Type="SpinnerType.Dots" Color="SpinnerColor.Primary" Visible="@visible" />
@if (ID==0)
{
<label for="user-name" class="block mb-2 text-slate-600 font-bold">
شماره همراه / نام کاربری
</label>
<div class="d-flex">
@if (ID==0)
{
<label for="user-name" class="block mb-2 text-slate-600 font-bold">
شماره همراه / نام کاربری
</label>
<div class="d-flex">
<div class="container-input" style="width:150px;margin-left:5px">
<input disabled="@visible" style="text-align:center;height:30px" type="number" id="user-name" maxlength="64"
@bind-value=Username title="نام کاربری را وارد کنید." class="input-form input_vk_1" required="" data-val="true" data-val-required="شماره همراه / نام کاربری را وارد کنید." name="Username">
<div class="container-input" style="width:150px;margin-left:5px">
<input type="text"
id="user-name"
maxlength="13"
style="text-align:center;height:30px;@validateStyleUser"
title="شماره همراه را وارد کنید. مثل 0911-966-0045"
class="input-form input_vk_1"
required
data-val="true"
data-val-required="شماره همراه را وارد کنید."
name="Username"
oninput="formatPhoneNumber(this)"
@bind-value=Username>
</div>
<Button disabled="visible" Color="ButtonColor.Primary" Type="ButtonType.Submit" @onclick="Login" class="btn-primary"
style="text-align:center;height:30px">
ورود
</Button>
</div>
}
else{
<label for="user-name" class="block mb-2 text-slate-600 font-bold">
جهت احراز کد ارسال شده را وارد کنید
</label>
<div class="d-flex justify-content-center">
<div class="verification-inputs" style="display: flex; gap: 8px; direction: ltr;">
<input maxlength="1" type="text" inputmode="numeric" pattern="[0-9]*"
@bind="code1" @oninput="MoveNext"
style="width: 45px; height: 45px; text-align: center; border: 2px solid #ccc; border-radius: 8px; font-size: 18px; font-weight: bold;"
@ref="input1" autoFocus />
<input maxlength="1" type="text" inputmode="numeric" pattern="[0-9]*"
@bind="code2" @oninput="MoveNext"
style="width: 45px; height: 45px; text-align: center; border: 2px solid #ccc; border-radius: 8px; font-size: 18px; font-weight: bold;"
@ref="input2" />
<input maxlength="1" type="text" inputmode="numeric" pattern="[0-9]*"
@bind="code3" @oninput="MoveNext"
style="width: 45px; height: 45px; text-align: center; border: 2px solid #ccc; border-radius: 8px; font-size: 18px; font-weight: bold;"
@ref="input3" />
<input maxlength="1" type="text" inputmode="numeric" pattern="[0-9]*"
@bind="code4" @oninput="OnLastInput"
style="width: 45px; height: 45px; text-align: center; border: 2px solid #ccc; border-radius: 8px; font-size: 18px; font-weight: bold;"
@ref="input4" />
</div>
</div>
<Button disabled="visible" Color="ButtonColor.Primary" Type="ButtonType.Submit" @onclick="Login" class="btn-primary"
style="text-align:center;height:30px">
ورود
</Button>
</div>
}
else{
<label for="user-name" class="block mb-2 text-slate-600 font-bold">
جهت احراز کد ارسال شده را وارد کنید
</label>
<div class="d-flex justify-content-center">
<div class="verification-inputs" style="display: flex; gap: 8px; direction: ltr;">
<input maxlength="1" type="text" inputmode="numeric" pattern="[0-9]*"
@bind="code1" @oninput="MoveNext"
style="width: 45px; height: 45px; text-align: center; border: 2px solid #ccc; border-radius: 8px; font-size: 18px; font-weight: bold;"
@ref="input1" autoFocus />
<input maxlength="1" type="text" inputmode="numeric" pattern="[0-9]*"
@bind="code2" @oninput="MoveNext"
style="width: 45px; height: 45px; text-align: center; border: 2px solid #ccc; border-radius: 8px; font-size: 18px; font-weight: bold;"
@ref="input2" />
<input maxlength="1" type="text" inputmode="numeric" pattern="[0-9]*"
@bind="code3" @oninput="MoveNext"
style="width: 45px; height: 45px; text-align: center; border: 2px solid #ccc; border-radius: 8px; font-size: 18px; font-weight: bold;"
@ref="input3" />
<input maxlength="1" type="text" inputmode="numeric" pattern="[0-9]*"
@bind="code4" @oninput="OnLastInput"
style="width: 45px; height: 45px; text-align: center; border: 2px solid #ccc; border-radius: 8px; font-size: 18px; font-weight: bold;"
@ref="input4" />
</div>
</div>
}
}
</div>
</div>
@@ -70,17 +82,27 @@
//-----------------
private string code1, code2, code3, code4;
private ElementReference input1, input2, input3, input4;
string validateStyleUser="";
}
@functions{
async Task Login()
{
visible = true;
ID= await AuthService.login(new Common.Models.Auth.UserSide.AuthRequestFromUserSide()
if (Username.Replace("-","").CheckMobile())
{
Mobile=Username
});
visible = false;
visible = true;
ID = await AuthService.login(new Common.Models.Auth.UserSide.AuthRequestFromUserSide()
{
Mobile = Username.Replace("-", "")
});
validateStyleUser = "";
visible = false;
}
else
{
validateStyleUser =" border: 2px solid red; border-radius: 4px;";
}
}
async Task ver()
{
@@ -119,7 +141,27 @@
}
}
}
<script>
function formatPhoneNumber(input) {
let value = input.value.replace(/\D/g, ''); // فقط عدد
if (value.length > 11) value = value.slice(0, 11); // حداکثر 11 رقم
let formatted = '';
if (value.length >= 4) {
formatted += value.slice(0, 4) + '-';
if (value.length >= 7) {
formatted += value.slice(4, 7) + '-';
formatted += value.slice(7);
} else {
formatted += value.slice(4);
}
} else {
formatted = value;
}
input.value = formatted;
}
</script>
<style>
.login-form {
width: 100%;

View File

@@ -60,16 +60,10 @@ namespace HushianWebApp.Service
var response = await _baseController.Post($"v1/Auth/AuthenticationFromUser",model);
if (response.IsSuccessStatusCode)
return await response.Content.ReadFromJsonAsync<int>();
else if (response.StatusCode == System.Net.HttpStatusCode.BadRequest)
{
var Errors = await response.Content.ReadFromJsonAsync<List<string>>();
_ToastService.Notify(new ToastMessage(ToastType.Danger, Errors[0].Split(':').Length == 2 ? Errors[0].Split(':')[1] : Errors[0]));
}
else if (!response.IsSuccessStatusCode)
else
{
_NavigationManager.NavigateTo("Unhandled");
_ToastService.Notify(new ToastMessage(ToastType.Danger, "کاربر یافت نشد"));
}
return 0;