104 lines
3.1 KiB
Plaintext
Executable File
104 lines
3.1 KiB
Plaintext
Executable File
@page "/SignIn"
|
|
@page "/confirm-account/{*token}"
|
|
@layout EmptyLayout
|
|
@inject UserAPIConsumer userAPIConsumer
|
|
@inject NavigationManager nav
|
|
|
|
|
|
<PageTitle>Sign In</PageTitle>
|
|
|
|
|
|
|
|
|
|
<EditForm Model="@tokenRequestModel" OnValidSubmit="@OnValidSignIn"
|
|
class="flex justify-center items-center h-screen bg-base-200">
|
|
<DataAnnotationsValidator />
|
|
|
|
<div class="card w-96 bg-base-100 shadow-xl">
|
|
<div class="card-body">
|
|
<h2 class="card-title text-2xl font-bold justify-center mb-6">Sign In</h2>
|
|
|
|
<div class="form-control w-full max-w-xs mx-auto">
|
|
<label class="label">
|
|
<span class="label-text">Email</span>
|
|
</label>
|
|
<InputText type="email" placeholder="email@example.com" @bind-Value="tokenRequestModel.Email"
|
|
class="input input-bordered w-full max-w-xs" />
|
|
</div>
|
|
|
|
<div class="form-control w-full max-w-xs mx-auto">
|
|
<label class="label">
|
|
<span class="label-text">Password</span>
|
|
</label>
|
|
<InputText type="password" placeholder="********" @bind-Value="tokenRequestModel.Password"
|
|
class="input input-bordered w-full max-w-xs" />
|
|
<label class="label">
|
|
<a href="/ForgotPassword" class="label-text-alt link link-hover">Forgot Password?</a>
|
|
</label>
|
|
</div>
|
|
|
|
<div class="card-actions justify-center mt-6">
|
|
<button type="submit" class="btn btn-primary w-full max-w-xs">Sign In</button>
|
|
</div>
|
|
|
|
@if (!string.IsNullOrEmpty(errorMessage))
|
|
{
|
|
<div class="alert alert-error mt-4">
|
|
<span>@errorMessage</span>
|
|
</div>
|
|
}
|
|
</div>
|
|
</div>
|
|
</EditForm>
|
|
|
|
|
|
|
|
|
|
@code {
|
|
|
|
[Parameter]
|
|
public string? Token { get; set; }
|
|
|
|
private TokenRequestModel tokenRequestModel = new();
|
|
private string errorMessage = "";
|
|
|
|
|
|
[CascadingParameter] public Task<AuthenticationState> authStateTask { get; set; }
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
var user = (await authStateTask).User;
|
|
if (user != null)
|
|
if (user.Identity.IsAuthenticated)
|
|
nav.NavigateTo("/");
|
|
}
|
|
|
|
public async Task OnValidSignIn()
|
|
{
|
|
var isSuccessful = await userAPIConsumer.Login(tokenRequestModel);
|
|
if (isSuccessful)
|
|
{
|
|
if (!string.IsNullOrEmpty(Token))
|
|
{
|
|
var confirmSuccessful = await userAPIConsumer.ConfirmEmail(Token);
|
|
if (confirmSuccessful)
|
|
nav.NavigateTo("/email-confirmed");
|
|
else
|
|
{
|
|
errorMessage = "Error, confirming email. try again later.";
|
|
}
|
|
}
|
|
else
|
|
nav.NavigateTo("/");
|
|
}
|
|
else
|
|
errorMessage = "Wrong Email or Password.";
|
|
|
|
|
|
|
|
|
|
|
|
@* errorMessage = result.Message; *@
|
|
}
|
|
|
|
} |