diff --git a/FWLAZ_Web/AppSettings.cs b/FWLAZ_Web/AppSettings.cs new file mode 100644 index 0000000..ad49bad --- /dev/null +++ b/FWLAZ_Web/AppSettings.cs @@ -0,0 +1,7 @@ +namespace FWLAZ_Web +{ + public class AppSettings + { + public bool RegistrationEnabled { get; set; } + } +} diff --git a/FWLAZ_Web/Components/Account/Pages/Login.razor b/FWLAZ_Web/Components/Account/Pages/Login.razor index 146890a..b9895f9 100644 --- a/FWLAZ_Web/Components/Account/Pages/Login.razor +++ b/FWLAZ_Web/Components/Account/Pages/Login.razor @@ -4,11 +4,13 @@ @using Microsoft.AspNetCore.Authentication @using Microsoft.AspNetCore.Identity @using FWLAZ_Web.Data +@using Microsoft.Extensions.Options @inject SignInManager SignInManager @inject ILogger Logger @inject NavigationManager NavigationManager @inject IdentityRedirectManager RedirectManager +@inject IOptions Config; Log in @@ -45,9 +47,12 @@

Forgot your password?

-

- { ["ReturnUrl"] = ReturnUrl }))">Register as a new user -

+ @if (Config.Value.RegistrationEnabled) + { +

+ { ["ReturnUrl"] = ReturnUrl }))">Register as a new user +

+ }

Resend email confirmation

diff --git a/FWLAZ_Web/Components/Account/Pages/Register.razor b/FWLAZ_Web/Components/Account/Pages/Register.razor index 2ff692b..29b700d 100644 --- a/FWLAZ_Web/Components/Account/Pages/Register.razor +++ b/FWLAZ_Web/Components/Account/Pages/Register.razor @@ -6,6 +6,7 @@ @using Microsoft.AspNetCore.Identity @using Microsoft.AspNetCore.WebUtilities @using FWLAZ_Web.Data +@using Microsoft.Extensions.Options @inject UserManager UserManager @inject IUserStore UserStore @@ -14,9 +15,17 @@ @inject ILogger Logger @inject NavigationManager NavigationManager @inject IdentityRedirectManager RedirectManager +@inject IOptions Config; + Register +@if (!Config.Value.RegistrationEnabled) +{ + RedirectManager.RedirectTo("/"); +} + +

Register

diff --git a/FWLAZ_Web/Program.cs b/FWLAZ_Web/Program.cs index 5838ee7..9b6542e 100644 --- a/FWLAZ_Web/Program.cs +++ b/FWLAZ_Web/Program.cs @@ -6,9 +6,13 @@ using FWLAZ_Web.Objects; using FWLAZ_Web.Components.Account; using Microsoft.AspNetCore.Components.Authorization; using Microsoft.AspNetCore.Identity; +using FWLAZ_Web; var builder = WebApplication.CreateBuilder(args); + +// AppSettings auslesen var connectionstring = builder.Configuration.GetConnectionString("QuizDB"); +builder.Services.Configure(builder.Configuration.GetSection(nameof(AppSettings))); // Add services to the container. builder.Services.AddRazorComponents() diff --git a/FWLAZ_Web/appsettings.json b/FWLAZ_Web/appsettings.json index 5967930..6420e5c 100644 --- a/FWLAZ_Web/appsettings.json +++ b/FWLAZ_Web/appsettings.json @@ -8,5 +8,8 @@ "ConnectionStrings": { "QuizDB": "Data Source=Data/quiz.db" }, + "AppSettings": { + "RegistrationEnabled": true + }, "AllowedHosts": "*" }