mirror of
https://github.com/chylex/Minecraft-Phantom-Panel.git
synced 2025-05-10 08:34:11 +02:00
60 lines
1.5 KiB
Plaintext
60 lines
1.5 KiB
Plaintext
@page "/login"
|
|
@using Phantom.Web.Services
|
|
@using Phantom.Web.Services.Authentication
|
|
@using System.ComponentModel.DataAnnotations
|
|
@attribute [AllowAnonymous]
|
|
@inject Navigation Navigation
|
|
@inject UserLoginManager LoginManager
|
|
|
|
<h1>Login</h1>
|
|
|
|
<Form Model="form" OnSubmit="DoLogin">
|
|
<div style="max-width: 400px;">
|
|
<div class="row">
|
|
<div class="mb-3">
|
|
<FormTextInput Id="account-username" Label="Username" @bind-Value="form.Username" />
|
|
</div>
|
|
</div>
|
|
|
|
<div class="row">
|
|
<div class="mb-3">
|
|
<FormTextInput Id="account-password" Label="Password" Type="FormTextInputType.Password" @bind-Value="form.Password" />
|
|
</div>
|
|
</div>
|
|
|
|
<FormButtonSubmit Label="Login" class="btn btn-primary" />
|
|
</div>
|
|
|
|
<FormSubmitError />
|
|
</Form>
|
|
|
|
@code {
|
|
|
|
private readonly LoginFormModel form = new ();
|
|
|
|
private sealed class LoginFormModel : FormModel {
|
|
[Required]
|
|
public string Username { get; set; } = string.Empty;
|
|
|
|
[Required]
|
|
public string Password { get; set; } = string.Empty;
|
|
}
|
|
|
|
protected override void OnInitialized() {
|
|
if (Navigation.GetQueryParameter("token", out _)) {
|
|
form.SubmitModel.StopSubmitting("Please login again.");
|
|
}
|
|
}
|
|
|
|
private async Task DoLogin(EditContext context) {
|
|
await form.SubmitModel.StartSubmitting();
|
|
|
|
string? returnUrl = Navigation.GetQueryParameter("return", out var url) ? url : null;
|
|
|
|
if (!await LoginManager.LogIn(form.Username, form.Password, returnUrl)) {
|
|
form.SubmitModel.StopSubmitting("Invalid username or password.");
|
|
}
|
|
}
|
|
|
|
}
|