118 lines
4.7 KiB
Text
118 lines
4.7 KiB
Text
@page "/Settings/Authentication"
|
|
@using CaseConverter
|
|
@using LANCommander.SDK.Extensions
|
|
@using LANCommander.Server.Settings
|
|
@using LANCommander.Server.UI.Pages.Settings.Authentication.Components
|
|
@using Microsoft.Extensions.Options
|
|
@inject IMessageService MessageService
|
|
@inject ILogger<Index> Logger
|
|
@inject IServiceProvider ServiceProvider
|
|
@inject IOptions<Settings> Settings
|
|
@inject SettingsProvider<Settings> SettingsProvider
|
|
@attribute [Authorize(Roles = RoleService.AdministratorRoleName)]
|
|
|
|
<PageHeader Title="Authentication">
|
|
<PageHeaderExtra>
|
|
<Button OnClick="Save" Type="@ButtonType.Primary">Save</Button>
|
|
</PageHeaderExtra>
|
|
</PageHeader>
|
|
|
|
<PageContent>
|
|
<Form Model="Settings.Value" Layout="@FormLayout.Vertical">
|
|
<FormItem Label="Allow Registration">
|
|
<Switch @bind-Checked="context.Server.Authentication.AllowRegistration" />
|
|
</FormItem>
|
|
|
|
<FormItem Label="Require Account Approval">
|
|
<Switch @bind-Checked="context.Server.Authentication.RequireApproval" />
|
|
</FormItem>
|
|
|
|
<FormItem Label="Auto-redirect to external provider">
|
|
<Switch @bind-Checked="context.Server.Authentication.AutoRedirectToProvider" />
|
|
</FormItem>
|
|
|
|
<FormItem Label="Token Secret">
|
|
<InputPassword @bind-Value="context.Server.Authentication.TokenSecret" />
|
|
</FormItem>
|
|
<FormItem Label="Token Lifetime">
|
|
<AntDesign.InputNumber @bind-Value="context.Server.Authentication.TokenLifetime" Formatter="FormatTokenLifetime" Min="1" />
|
|
</FormItem>
|
|
|
|
<Divider Text="Password Requirements" />
|
|
|
|
<FormItem Label="Require non-alphanumeric characters">
|
|
<Switch @bind-Checked="@context.Server.Authentication.PasswordRequireNonAlphanumeric" />
|
|
</FormItem>
|
|
<FormItem Label="Require Lowercase characters">
|
|
<Switch @bind-Checked="context.Server.Authentication.PasswordRequireLowercase" />
|
|
</FormItem>
|
|
<FormItem Label="Require Uppercase characters">
|
|
<Switch @bind-Checked="context.Server.Authentication.PasswordRequireUppercase" />
|
|
</FormItem>
|
|
<FormItem Label="Require digits">
|
|
<Switch @bind-Checked="context.Server.Authentication.PasswordRequireDigit" />
|
|
</FormItem>
|
|
<FormItem Label="Minimum Length">
|
|
<AntDesign.InputNumber @bind-Value="context.Server.Authentication.PasswordRequiredLength" Min="1" />
|
|
</FormItem>
|
|
|
|
<Divider Text="Security" />
|
|
|
|
<Collapse>
|
|
<Panel Header="HTTP">
|
|
<FormItem Label="Minimum Same Site Cookie Policy">
|
|
<EnumSelect TEnum="SameSiteMode" @bind-Value="context.Server.Authentication.HttpCookiePolicy.SameSite" />
|
|
</FormItem>
|
|
<FormItem Label="Cookie Secure Policy">
|
|
<EnumSelect TEnum="CookieSecurePolicy" @bind-Value="context.Server.Authentication.HttpCookiePolicy.Secure" />
|
|
</FormItem>
|
|
</Panel>
|
|
|
|
<Panel Header="HTTPS">
|
|
<FormItem Label="Minimum Same Site Cookie Policy">
|
|
<EnumSelect TEnum="SameSiteMode" @bind-Value="context.Server.Authentication.HttpsCookiePolicy.SameSite" />
|
|
</FormItem>
|
|
<FormItem Label="Cookie Secure Policy">
|
|
<EnumSelect TEnum="CookieSecurePolicy" @bind-Value="context.Server.Authentication.HttpsCookiePolicy.Secure" />
|
|
</FormItem>
|
|
</Panel>
|
|
</Collapse>
|
|
</Form>
|
|
|
|
<Divider Text="External Providers" />
|
|
|
|
<Alert Type="@AlertType.Info" Message="A server restart is required for changes to authentication providers to take effect." ShowIcon="true" Style="margin-bottom: 16px;" />
|
|
|
|
<ExternalProviderEditor @bind-Values="Settings.Value.Server.Authentication.AuthenticationProviders" />
|
|
</PageContent>
|
|
|
|
@code {
|
|
string FormatTokenLifetime(int value)
|
|
{
|
|
return value.ToString() + " days";
|
|
}
|
|
|
|
void Save()
|
|
{
|
|
try
|
|
{
|
|
SettingsProvider.Update(s =>
|
|
{
|
|
foreach (var authenticationProvider in Settings.Value.Server.Authentication.AuthenticationProviders)
|
|
{
|
|
if (String.IsNullOrWhiteSpace(authenticationProvider.Slug))
|
|
authenticationProvider.Slug = authenticationProvider.Name.ToPascalCase();
|
|
}
|
|
|
|
s.Server.Authentication = Settings.Value.Server.Authentication;
|
|
});
|
|
|
|
MessageService.Success("Settings saved!");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageService.Error("An unknown error occurred.");
|
|
Logger.LogError(ex, "An unknown error occurred.");
|
|
}
|
|
}
|
|
}
|