Merge pull request #390 from Moonlight-Panel/v2_AddRegisterDeny

Added the option to disable register
This commit is contained in:
Masu Baumgartner 2024-04-22 18:23:48 +02:00 committed by GitHub
commit c553f6f5da
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 59 additions and 39 deletions

View file

@ -69,6 +69,10 @@ public class CoreConfiguration
[JsonProperty("TokenDuration")]
[Description("This specifies the duration the token of an user will be valid. The value specifies the days")]
public int TokenDuration { get; set; } = 30;
[JsonProperty("DenyRegister")]
[Description("This disables the register function. No user will be able to sign up anymore. Its recommended to enable this for private instances")]
public bool DenyRegister { get; set; } = false;
}
public class SecurityData

View file

@ -6,16 +6,28 @@
@using Moonlight.Core.Models.Forms
@using Moonlight.Core.Services
@using MoonCore.Exceptions
@using MoonCore.Services
@using MoonCoreUI.Services
@using Moonlight.Core.Configuration
@inject IAuthenticationProvider AuthenticationProvider
@inject IdentityService IdentityService
@inject CookieService CookieService
@inject NavigationManager Navigation
@inject ConfigService<CoreConfiguration> ConfigService
<div class="d-flex justify-content-center">
<div class="d-flex align-items-center">
<div class="card card-body m-15 p-15">
@if (ConfigService.Get().Authentication.DenyRegister)
{
<IconAlert Color="danger" Icon="bx-shield-quarter" Title="Sign up disabled">
The administrator of this instance has disabled to sign up function<br />
Back to <a href="/login">login</a>
</IconAlert>
}
else
{
<div class="text-center mb-8">
<div class="fw-bold mb-3 fs-1">
Register
@ -57,6 +69,7 @@
</div>
</div>
</SmartForm>
}
</div>
</div>
</div>
@ -67,6 +80,9 @@
private async Task OnValidSubmit()
{
if (ConfigService.Get().Authentication.DenyRegister)
throw new DisplayException("The sign up function has been disabled");
if (Form.Password != Form.RepeatedPassword)
throw new DisplayException("The passwords do not match");