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) public static bool CheckUsername(this string Username)
=> (Username.Length == 11 && Username.StartsWith("09")) => (Username.Length == 11 && Username.StartsWith("09"))
|| (Username.Length == 9 && Username.StartsWith("E/")); || (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) public static bool IsValidEmail(this string email)
{ {
// الگوی ساده اما معتبر برای بررسی ایمیل // الگوی ساده اما معتبر برای بررسی ایمیل

View File

@@ -1,5 +1,7 @@
@using HushianWebApp.Service @using Common.Validation
@using HushianWebApp.Service
@inject AuthService AuthService @inject AuthService AuthService
@inject VerificationService verificationService;
<div class="login-form"> <div class="login-form">
<div class="text-center mb-4"> <div class="text-center mb-4">
<span class="badge bg-info p-2 rounded-pill">نیاز برای ارتباط با کارشناسان وارد شود</span> <span class="badge bg-info p-2 rounded-pill">نیاز برای ارتباط با کارشناسان وارد شود</span>
@@ -9,15 +11,25 @@
@if (ID==0) @if (ID==0)
{ {
<label for="user-name" class="block mb-2 text-slate-600 font-bold"> <label for="user-name" class="block mb-2 text-slate-600 font-bold">
شماره همراه / نام کاربری شماره همراه / نام کاربری
</label> </label>
<div class="d-flex"> <div class="d-flex">
<div class="container-input" style="width:150px;margin-left:5px"> <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" <input type="text"
@bind-value=Username title="نام کاربری را وارد کنید." class="input-form input_vk_1" required="" data-val="true" data-val-required="شماره همراه / نام کاربری را وارد کنید." name="Username"> 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> </div>
<Button disabled="visible" Color="ButtonColor.Primary" Type="ButtonType.Submit" @onclick="Login" class="btn-primary" <Button disabled="visible" Color="ButtonColor.Primary" Type="ButtonType.Submit" @onclick="Login" class="btn-primary"
style="text-align:center;height:30px"> style="text-align:center;height:30px">
@@ -70,18 +82,28 @@
//----------------- //-----------------
private string code1, code2, code3, code4; private string code1, code2, code3, code4;
private ElementReference input1, input2, input3, input4; private ElementReference input1, input2, input3, input4;
string validateStyleUser="";
} }
@functions{ @functions{
async Task Login() async Task Login()
{ {
visible = true; if (Username.Replace("-","").CheckMobile())
ID= await AuthService.login(new Common.Models.Auth.UserSide.AuthRequestFromUserSide()
{ {
Mobile=Username visible = true;
ID = await AuthService.login(new Common.Models.Auth.UserSide.AuthRequestFromUserSide()
{
Mobile = Username.Replace("-", "")
}); });
validateStyleUser = "";
visible = false; visible = false;
} }
else
{
validateStyleUser =" border: 2px solid red; border-radius: 4px;";
}
}
async Task ver() async Task ver()
{ {
visible = true; visible = true;
@@ -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> <style>
.login-form { .login-form {
width: 100%; width: 100%;

View File

@@ -60,16 +60,10 @@ namespace HushianWebApp.Service
var response = await _baseController.Post($"v1/Auth/AuthenticationFromUser",model); var response = await _baseController.Post($"v1/Auth/AuthenticationFromUser",model);
if (response.IsSuccessStatusCode) if (response.IsSuccessStatusCode)
return await response.Content.ReadFromJsonAsync<int>(); return await response.Content.ReadFromJsonAsync<int>();
else if (response.StatusCode == System.Net.HttpStatusCode.BadRequest) else
{
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)
{ {
_NavigationManager.NavigateTo("Unhandled"); _ToastService.Notify(new ToastMessage(ToastType.Danger, "کاربر یافت نشد"));
} }
return 0; return 0;