75 lines
2.9 KiB
Plaintext
75 lines
2.9 KiB
Plaintext
@using System.Net
|
|
@page "/Register"
|
|
|
|
@inject LoginService loginService
|
|
@inject NavigationManager navigation
|
|
|
|
<PageTitle>Register</PageTitle>
|
|
|
|
@if (_checkingStatus) {
|
|
<LoadSpinner/>
|
|
} else if (_registrationDisabled) {
|
|
<EmptyState Variant="warning" Title="Registration Closed">
|
|
<p>New user registration is currently disabled on this server.</p>
|
|
<a href="/login" class="btn btn-primary">Go to Login</a>
|
|
</EmptyState>
|
|
} else {
|
|
<div class="d-flex flex-column mx-sm-auto mx-3">
|
|
@if (!string.IsNullOrEmpty(_error)) {
|
|
<div class="m-2 p-1 border-danger border-2 rounded-3 bg-danger-subtle">
|
|
<div class="text-danger-emphasis m-2">@_error</div>
|
|
</div>
|
|
}
|
|
<form class="d-flex flex-column align-items-center">
|
|
<input type="text" class="form-control my-1" placeholder="Username" required="required" id="username"
|
|
@bind="_username" @bind:event="oninput"/>
|
|
<input type="email" class="form-control my-1" placeholder="Email" required="required" id="email"
|
|
@bind="_email" @bind:event="oninput"/>
|
|
|
|
<PasswordField @ref="_passwordField"
|
|
@bind-Password="_password"
|
|
@bind-ConfirmPassword="_confirmPassword" />
|
|
|
|
<div class="d-flex flex-row justify-content-around w-100 mt-2">
|
|
<button class="btn btn-primary m-2" type="button" id="register-button"
|
|
disabled="@(!CanSubmit)" @onclick="Register_OnClick">Register</button>
|
|
<a class="btn btn-primary m-2" id="login-button" href="/login">Login</a>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
}
|
|
|
|
@code {
|
|
PasswordField? _passwordField;
|
|
string _username = string.Empty;
|
|
string _email = string.Empty;
|
|
string _password = string.Empty;
|
|
string _confirmPassword = string.Empty;
|
|
string _error = string.Empty;
|
|
bool _checkingStatus = true;
|
|
bool _registrationDisabled;
|
|
|
|
bool CanSubmit => _passwordField?.IsValid == true
|
|
&& !string.IsNullOrWhiteSpace(_username)
|
|
&& !string.IsNullOrWhiteSpace(_email);
|
|
|
|
protected override async Task OnInitializedAsync() {
|
|
_registrationDisabled = !await loginService.IsRegistrationEnabledAsync();
|
|
_checkingStatus = false;
|
|
}
|
|
|
|
async Task Register_OnClick() {
|
|
_error = string.Empty;
|
|
var status = await loginService.Register(_username, _email, _password);
|
|
if (status == HttpStatusCode.OK) {
|
|
navigation.NavigateTo("login");
|
|
} else if (status == HttpStatusCode.Forbidden) {
|
|
_error = "Registration is currently disabled.";
|
|
} else if (status == HttpStatusCode.Conflict) {
|
|
_error = "Username or email already taken.";
|
|
} else {
|
|
_error = "Registration failed. Please try again.";
|
|
}
|
|
}
|
|
}
|