Merge pull request #390 from Moonlight-Panel/v2_AddRegisterDeny
Added the option to disable register
This commit is contained in:
commit
c553f6f5da
2 changed files with 59 additions and 39 deletions
|
@ -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
|
||||
|
|
|
@ -6,57 +6,70 @@
|
|||
@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">
|
||||
<div class="text-center mb-8">
|
||||
<div class="fw-bold mb-3 fs-1">
|
||||
Register
|
||||
</div>
|
||||
<div class="text-gray-400 fw-semibold fs-4">
|
||||
Register in order to start managing your services
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<SmartForm Model="Form" OnValidSubmit="OnValidSubmit">
|
||||
<div class="fv-row mb-8">
|
||||
<input @bind="Form.Username" type="text" placeholder="Username" class="form-control form-control-solid">
|
||||
</div>
|
||||
|
||||
<div class="fv-row mb-8">
|
||||
<input @bind="Form.Email" type="text" placeholder="Email" class="form-control form-control-solid">
|
||||
</div>
|
||||
|
||||
<div class="fv-row mb-7">
|
||||
<input @bind="Form.Password" type="password" placeholder="Password" class="form-control form-control-solid">
|
||||
</div>
|
||||
|
||||
<div class="fv-row mb-7">
|
||||
<input @bind="Form.RepeatedPassword" type="password" placeholder="Repeat your password" class="form-control form-control-solid">
|
||||
</div>
|
||||
|
||||
<div class="d-flex flex-stack flex-wrap gap-3 fs-base fw-semibold mb-10">
|
||||
<div></div>
|
||||
<a href="/login" class="link-primary">
|
||||
Already have an account ?
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="d-flex flex-stack">
|
||||
<button type="submit" class="btn btn-primary me-2 flex-shrink-0">Sign Up</button>
|
||||
<div class="d-flex align-items-center">
|
||||
<div class="text-gray-400 fw-semibold fs-6 me-3 me-md-6">Or</div>
|
||||
@* OAuth2 Providers here *@
|
||||
@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
|
||||
</div>
|
||||
<div class="text-gray-400 fw-semibold fs-4">
|
||||
Register in order to start managing your services
|
||||
</div>
|
||||
</div>
|
||||
</SmartForm>
|
||||
|
||||
<SmartForm Model="Form" OnValidSubmit="OnValidSubmit">
|
||||
<div class="fv-row mb-8">
|
||||
<input @bind="Form.Username" type="text" placeholder="Username" class="form-control form-control-solid">
|
||||
</div>
|
||||
|
||||
<div class="fv-row mb-8">
|
||||
<input @bind="Form.Email" type="text" placeholder="Email" class="form-control form-control-solid">
|
||||
</div>
|
||||
|
||||
<div class="fv-row mb-7">
|
||||
<input @bind="Form.Password" type="password" placeholder="Password" class="form-control form-control-solid">
|
||||
</div>
|
||||
|
||||
<div class="fv-row mb-7">
|
||||
<input @bind="Form.RepeatedPassword" type="password" placeholder="Repeat your password" class="form-control form-control-solid">
|
||||
</div>
|
||||
|
||||
<div class="d-flex flex-stack flex-wrap gap-3 fs-base fw-semibold mb-10">
|
||||
<div></div>
|
||||
<a href="/login" class="link-primary">
|
||||
Already have an account ?
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="d-flex flex-stack">
|
||||
<button type="submit" class="btn btn-primary me-2 flex-shrink-0">Sign Up</button>
|
||||
<div class="d-flex align-items-center">
|
||||
<div class="text-gray-400 fw-semibold fs-6 me-3 me-md-6">Or</div>
|
||||
@* OAuth2 Providers here *@
|
||||
</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");
|
||||
|
||||
|
|
Loading…
Reference in a new issue