70 lines
2.2 KiB
Plaintext
70 lines
2.2 KiB
Plaintext
@page "/administration/login"
|
|
@layout EmptyLayout
|
|
|
|
@using BlazorStrap
|
|
@using BlazorStrap.V5
|
|
@using HopFrame.Security.Models
|
|
@using HopFrame.Web.Pages.Administration.Layout
|
|
@using HopFrame.Web.Services
|
|
@using Microsoft.AspNetCore.Components.Web
|
|
@using Microsoft.AspNetCore.Components.Forms
|
|
|
|
<PageTitle>Login</PageTitle>
|
|
|
|
<div class="login-wrapper">
|
|
<div id="login-card">
|
|
<span id="login-title">HopFrame Administration</span>
|
|
<span id="login-subtitle">Login to proceed</span>
|
|
<EditForm Model="UserLogin" OnValidSubmit="Login" FormName="login-form" style="display: flex; flex-grow: 1; flex-direction: column">
|
|
<div class="mb-3">
|
|
<BSLabel>E-Mail address</BSLabel>
|
|
<InputText type="email" class="form-control" required @bind-Value="UserLogin.Email"/>
|
|
</div>
|
|
<div class="mb-3">
|
|
<BSLabel>Password</BSLabel>
|
|
<InputText type="password" class="form-control" required @bind-Value="UserLogin.Password"/>
|
|
</div>
|
|
|
|
@if (_hasError) {
|
|
<BSAlert Color="BSColor.Danger" style="margin-top: 16px; margin-bottom: 0">Email or password does not match any account!</BSAlert>
|
|
}
|
|
|
|
<BSButton Color="BSColor.Primary" IsSubmit="true" MarginTop="Margins.Auto" MarginLeftAndRight="Margins.Auto" style="width: 100px">Login</BSButton>
|
|
|
|
</EditForm>
|
|
</div>
|
|
</div>
|
|
|
|
@inject IAuthService Auth
|
|
@inject NavigationManager Navigator
|
|
|
|
@code {
|
|
[SupplyParameterFromForm]
|
|
private UserLogin UserLogin { get; set; }
|
|
|
|
[SupplyParameterFromQuery(Name = "redirect")]
|
|
public string RedirectAfter { get; set; }
|
|
|
|
private const string DefaultRedirect = "/administration";
|
|
|
|
private bool _hasError;
|
|
|
|
protected override async Task OnInitializedAsync() {
|
|
UserLogin ??= new();
|
|
|
|
if (await Auth.IsLoggedIn()) {
|
|
await Auth.Logout();
|
|
}
|
|
}
|
|
|
|
private async Task Login() {
|
|
var result = await Auth.Login(UserLogin);
|
|
|
|
if (!result) {
|
|
_hasError = true;
|
|
return;
|
|
}
|
|
|
|
Navigator.NavigateTo(string.IsNullOrEmpty(RedirectAfter) ? DefaultRedirect : RedirectAfter, true);
|
|
}
|
|
} |