This commit is contained in:
mmrbnjd
2024-04-18 00:33:46 +03:30
parent 3f3c283fef
commit fa5a83d8d3
7 changed files with 101 additions and 36 deletions

View File

@@ -2,6 +2,7 @@
@using Shared.DTOs
@inject HttpClient _hc
@inject NavigationManager nav
@inject UserAuthenticationDTO userinfo
<PageTitle>ثبت نام</PageTitle>
<main>
@@ -88,6 +89,9 @@
protected override async Task OnInitializedAsync()
{
if (userinfo!=null)
nav.NavigateTo("/");
editContext = new EditContext(model);
messageStore = new(editContext);
await base.OnInitializedAsync();

View File

@@ -1,6 +1,9 @@
@page "/Sign-in"
@using Shared.DTOs
@inject HttpClient _hc
@inject NavigationManager nav
@inject UserAuthenticationDTO userinfo
<PageTitle>ورود</PageTitle>
<main>
@@ -107,6 +110,15 @@
<button class="signin-btn ">ورود</button>
</div>
</EditForm>
<div class="row">
<Alert hidden="@Hidealert" Color="@alertColor" Dismissable="false">
<Icon Name="@alertIconName" class="me-2"></Icon>
@alertMessage
<Button Color="ButtonColor.Primary" @onclick="EndForm">اتمام عملیات</Button>
</Alert>
</div>
<div class="signin-banner-from-register">
<NavLink href="Register">اکانت ندارید؟ <span>ثبت نام</span></NavLink>
</div>
@@ -120,25 +132,46 @@
@code {
[SupplyParameterFromForm]
public Authentication? Model { get; set; }
public Authentication? Model { get; set; }
protected override void OnInitialized() => Model ??= new();
// alert
AlertColor alertColor = AlertColor.Primary;
IconName alertIconName = IconName.CheckCircleFill;
bool Hidealert = true;
string alertMessage = "";
// protected override async Task OnInitializedAsync()
// {
// var t1 = userinfo;
// var t2 = _hc;
// await base.OnInitializedAsync();
// }
}
@functions {
private void ShowDangerAlert(string msg)
{
Hidealert = false;
alertColor = AlertColor.Danger;
alertIconName = IconName.ExclamationTriangleFill;
alertMessage = msg;
}
private async Task EndForm() =>nav.NavigateTo("/");
private async Task OnLoginClick()
{
var request = await _hc.PostAsJsonAsync("User/authenticate", Model);
// if (request.IsSuccessStatusCode)
// {
// messageStore?.Clear();
// var VerificationID = await request.Content.ReadFromJsonAsync<int>();
// nav.NavigateTo($"Verification/{VerificationID}");
// }
// else
// {
// var error = await request.Content.ReadFromJsonAsync<List<string>>();
// messageStore?.Add(() => model.Mobile, error);
var request = await _hc.PostAsJsonAsync("User/authenticate", Model);
if (request.IsSuccessStatusCode)
{
userinfo = await request.Content.ReadFromJsonAsync<UserAuthenticationDTO>();
// }
_hc.DefaultRequestHeaders.Add("Authorization",
$"Bearer {userinfo?.Token}");
}
else if (request.StatusCode==System.Net.HttpStatusCode.NotFound)
ShowDangerAlert("کاربری با این مشخصات یافت نشد");
else ShowDangerAlert("خطای سیستمی");
}
}