Settings for the server are now combined with the settings from the SDK. This introduces a large breaking change and a migration should be created. This refactor utilizes .NET Configuration and the Options pattern. This will allow for the overriding of any setting using envionment variables. It also means that Settings.yml can be used to override any .NET configuration. A SettingsProvider implementation was created, and any updating of settings was changed from SettingsService.SaveSettings() to SettingsProvider.Update(s => { ... })
82 lines
No EOL
2.9 KiB
Text
82 lines
No EOL
2.9 KiB
Text
@page "/Profile/ConnectedAccounts"
|
|
@using LANCommander.Server.Settings
|
|
@using Microsoft.AspNetCore.Components.Authorization
|
|
@using Microsoft.Extensions.Options
|
|
@inject UserService UserService
|
|
@inject UserCustomFieldService UserCustomFieldService
|
|
@inject IOptions<Settings> Settings
|
|
@inject AuthenticationStateProvider AuthenticationStateProvider
|
|
@inject NavigationManager NavigationManager
|
|
@attribute [Authorize]
|
|
|
|
<PageHeader Title="Connected Accounts" />
|
|
|
|
<div style="padding: 0 24px">
|
|
<AntList DataSource="Settings.Value.Server.Authentication.AuthenticationProviders" Bordered Size="ListSize.Large">
|
|
<ListItem>
|
|
<Flex Align="FlexAlign.Center" Justify="FlexJustify.SpaceBetween" Style="width: 100%">
|
|
<Flex Align="FlexAlign.Center" Gap="FlexGap.Large">
|
|
@if (!String.IsNullOrWhiteSpace(context.Icon))
|
|
{
|
|
<BootstrapIcon Type="@context.Icon" Width="32px" Height="32px" Color="@(String.IsNullOrWhiteSpace(context.Color) ? "" : context.Color)"/>
|
|
}
|
|
|
|
<h3 style="margin: 0;">@context.Name</h3>
|
|
</Flex>
|
|
|
|
@{
|
|
var customField = CustomFields.FirstOrDefault(cf => cf.Name == context.GetCustomFieldName());
|
|
|
|
if (customField != null)
|
|
{
|
|
<Button Type="@ButtonType.Primary" OnClick="() => Unlink(customField)">Unlink</Button>
|
|
}
|
|
else
|
|
{
|
|
<Button Type="@ButtonType.Primary" OnClick="@(() => NavigationManager.NavigateTo($"/AccountLink?Provider={context.Slug}&ReturnUrl={NavigationManager.Uri}", true))">
|
|
Link
|
|
</Button>
|
|
}
|
|
}
|
|
</Flex>
|
|
</ListItem>
|
|
</AntList>
|
|
</div>
|
|
|
|
@code {
|
|
User User = new();
|
|
List<UserCustomField> CustomFields = new();
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
|
|
|
|
if (authState.User.Identity.IsAuthenticated)
|
|
{
|
|
User = await UserService.GetAsync(authState.User.Identity.Name);
|
|
}
|
|
|
|
await LoadData();
|
|
}
|
|
|
|
async Task LoadData()
|
|
{
|
|
foreach (var authenticationProvider in Settings.Value.Server.Authentication.AuthenticationProviders)
|
|
{
|
|
var customField = await UserCustomFieldService.FirstOrDefaultAsync(cf => cf.Name == authenticationProvider.GetCustomFieldName() && cf.UserId == User.Id);
|
|
|
|
if (customField != null)
|
|
CustomFields.Add(customField);
|
|
}
|
|
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
|
|
async Task Unlink(UserCustomField customField)
|
|
{
|
|
await UserCustomFieldService.DeleteAsync(customField.UserId.Value, customField.Name);
|
|
|
|
await LoadData();
|
|
}
|
|
|
|
} |