Implemented disabling signup using Features.NativeSignup configuration key
Some checks failed
Build, Tag, Push Docker Image / build (push) Has been cancelled
Create Release / Generate Release (push) Has been cancelled

This commit is contained in:
Mia Rose Winter 2024-03-17 14:11:13 +01:00
parent cc5a61fc09
commit d2d66b6017
Signed by: miawinter
GPG key ID: 4B6F6A83178F595E
7 changed files with 121 additions and 106 deletions

View file

@ -5,8 +5,10 @@
@using System.Text.Encodings.Web
@using Microsoft.AspNetCore.Identity
@using Microsoft.AspNetCore.WebUtilities
@using Microsoft.Extensions.Options
@using Wave.Data
@inject IOptions<Features> Features
@inject UserManager<ApplicationUser> UserManager
@inject IUserStore<ApplicationUser> UserStore
@inject SignInManager<ApplicationUser> SignInManager
@ -25,9 +27,10 @@
<PageTitle>@Localizer["Title"]</PageTitle>
<StatusMessage Message="@Message" />
<div class="flex gap-y-4 gap-x-8 flex-wrap h-full place-content-center">
<section class="w-80 max-w-xs">
<h2 class="text-2xl lg:text-4xl mb-3">@Localizer["Title"]</h2>
<BoardComponent CenterContent="true">
<BoardCardComponent Heading="@Localizer["Title"]">
@if (Features.Value.NativeSignup) {
<EditForm Model="Input" asp-route-returnUrl="@ReturnUrl" method="post" OnValidSubmit="RegisterUser"
FormName="register" class="w-full">
<DataAnnotationsValidator />
@ -51,17 +54,13 @@
@Localizer["Submit"]
</button>
</EditForm>
</section>
<!--
<div class="col-md-6 col-md-offset-2">
<section>
<h3>Use another service to register.</h3>
<hr />
<ExternalLoginPicker />
</section>
</div>
-->
</div>
} else {
<Alert CanRemove="false" Type="Alert.MessageType.Warning">
<p><strong>@Localizer["SignupDisabled_Message"]</strong></p>
</Alert>
}
</BoardCardComponent>
</BoardComponent>
@code {
private IEnumerable<IdentityError>? _identityErrors;
@ -77,6 +76,7 @@
$"Error: {string.Join(", ", _identityErrors.Select(error => error.Description))}";
public async Task RegisterUser(EditContext editContext) {
if (Features.Value.NativeSignup is false) return;
var user = CreateUser();
await UserStore.SetUserNameAsync(user, Input.Email, CancellationToken.None);

View file

@ -1,5 +1,5 @@
@using System.Globalization
<div class="alert @GetClass shadow" role="alert">
<div class="alert @GetClass shadow hyphens-auto" lang="@CultureInfo.CurrentCulture" role="alert">
<div>
@* ReSharper disable once SwitchStatementMissingSomeEnumCasesNoDefault *@
@switch (Type) {

View file

@ -1,7 +1,10 @@
@using System.Security.Claims
@using Microsoft.Extensions.Options
@using Wave.Data
@implements IDisposable
@inject NavigationManager NavigationManager
@inject IOptions<Features> Features
@inject IStringLocalizer<NavMenu> Localizer
<div class="h-12 hidden md:block" role="banner" aria-label="logo">
@ -79,11 +82,13 @@
</svg>
</NavLink>
</li>
@if (Features.Value.NativeSignup) {
<li>
<NavLink href="Account/Register">
@Localizer["SignUp_Label"]
</NavLink>
</li>
}
</NotAuthorized>
</AuthorizeView>
</ul>

View file

@ -63,7 +63,7 @@ public class SitemapController(ApplicationDbContext context, IOptions<Features>
}
root.Add(CreateUrlElement(nameSpace, new Uri(host, "/Account/Login")));
root.Add(CreateUrlElement(nameSpace, new Uri(host, "/Account/Register")));
if (Features.NativeSignup) root.Add(CreateUrlElement(nameSpace, new Uri(host, "/Account/Register")));
if (Features.EmailSubscriptions) root.Add(CreateUrlElement(nameSpace, new Uri(host, "/Email/Subscribe")));
document.Add(root);

View file

@ -3,4 +3,5 @@
public class Features {
public bool Rss { get; set; } = true;
public bool EmailSubscriptions { get; set; } = false;
public bool NativeSignup { get; set; } = true;
}

View file

@ -119,4 +119,10 @@
<data name="ConfirmPassword_Placeholder" xml:space="preserve">
<value>Passwort</value>
</data>
<data name="Email_Placeholder" xml:space="preserve">
<value>name@example.de</value>
</data>
<data name="SignupDisabled_Message" xml:space="preserve">
<value>Registrationen wurden auf diesem Server deaktiviert.</value>
</data>
</root>

View file

@ -122,4 +122,7 @@
<data name="Submit" xml:space="preserve">
<value>Sign Up Now</value>
</data>
<data name="SignupDisabled_Message" xml:space="preserve">
<value>Sign up has been disabled on this server. </value>
</data>
</root>