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