@using Common.Validation @using HushianWebApp.Service @using HushianWebApp.Services @inject AuthService AuthService @inject VerificationService verificationService; @inject NavigationManager navigationManager; @page "/UserPanelLogin" @layout UserPanelLayout @inject ILocalStorageService localStorageService; @inject ChatService chatService;

ورود به سیستم

@code { private bool visible = false; public string Username { get; set; } public int ID { get; set; } = 0; private string _code = string.Empty; public string Code { get { return _code; } set { _code=value; if (value.Length == 4) ver().ConfigureAwait(true); } } //----------------- // private string code1, code2, code3, code4; private ElementReference input1, input2, input3, input4; string validateStyleUser = ""; private bool isButtonDisabled = true; private int countdown = 60; private System.Timers.Timer? timer; } @functions { async Task Login() { if (Username.Replace("-", "").CheckMobile()) { visible = true; ID = await AuthService.login(new Common.Models.Auth.UserSide.AuthRequestFromUserSide() { Mobile = Username.Replace("-", "") }); validateStyleUser = ""; await verifiTimer(); visible = false; } else { validateStyleUser = " border: 2px solid red; border-radius: 4px;"; } } async Task verifiTimer() { //---------- isButtonDisabled = true; countdown = 60; timer = new System.Timers.Timer(1000); // هر 1 ثانیه timer.Elapsed += OnTimerElapsed; timer.AutoReset = true; timer.Enabled = true; //---------- } private void OnTimerElapsed(object? sender, System.Timers.ElapsedEventArgs e) { if (countdown > 0) { countdown--; InvokeAsync(StateHasChanged); // بروزرسانی UI } if (countdown == 0) { isButtonDisabled = false; timer?.Stop(); timer?.Dispose(); StateHasChanged(); } } async Task ver() { visible = true; if (await AuthService.Verificationlogin(ID, Code)) { int CompanyID = await localStorageService.GetItem("CompanyID"); int GroupID = await localStorageService.GetItem("GroupID"); int ChatID = await localStorageService.GetItem("ChatID"); if (CompanyID==null || CompanyID == 0) { var response= await chatService.GetLastChat(); CompanyID = response.Value.Item2; ChatID = response.Value.Item1; //---------------------------------------- if (CompanyID!=null && CompanyID!=0) await localStorageService.SetItem("CompanyID", CompanyID); if (ChatID!=null && ChatID!=0) { await localStorageService.RemoveItem("ChatID"); await localStorageService.SetItem("ChatID", ChatID); } } string route = $"UserCP/{CompanyID}"; if (ChatID!=null && ChatID!=0) route += $"?ChatID={ChatID}"; if (GroupID!=null && GroupID!=0 && !(ChatID!=null && ChatID!=0)) route += $"?GroupID={GroupID}"; navigationManager.NavigateTo(route); } visible = false; } // 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(code4) && code4.Length == 1) // { // Code = $"{code1}{code2}{code3}{code4}"; // await ver(); // } // } }