...
This commit is contained in:
@@ -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("خطای سیستمی");
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user