- add: multiauth
This commit is contained in:
@@ -24,8 +24,9 @@ account-auth-server = Authentication Server
|
|||||||
account-auth-button = Authenticate
|
account-auth-button = Authenticate
|
||||||
account-auth-save = Save Profile
|
account-auth-save = Save Profile
|
||||||
account-auth-hello = Hello,
|
account-auth-hello = Hello,
|
||||||
|
account-auth-current-server = Current server auth:
|
||||||
account-auth-logout = Log out
|
account-auth-logout = Log out
|
||||||
auth-current-login-name = Current login: {$login}
|
auth-current-login-name = Current login {$auth_server}: {$login}
|
||||||
auth-current-login-no-name = Profile not selected
|
auth-current-login-no-name = Profile not selected
|
||||||
|
|
||||||
auth-processing = Processing authentication request...
|
auth-processing = Processing authentication request...
|
||||||
@@ -37,6 +38,7 @@ auth-name-resolution-error = Failed to resolve server address. Check your networ
|
|||||||
auth-secure-error = Failed to cinnect to the server using SSL
|
auth-secure-error = Failed to cinnect to the server using SSL
|
||||||
auth-config-read = Reading authentication configuration...
|
auth-config-read = Reading authentication configuration...
|
||||||
auth-try-auth-config = Attempting to authenticate using saved configuration.
|
auth-try-auth-config = Attempting to authenticate using saved configuration.
|
||||||
|
auth-try-auth-profile = Attempting to authenticate using profile
|
||||||
|
|
||||||
config-export-logs = Export logs
|
config-export-logs = Export logs
|
||||||
config-open-data = Open data path
|
config-open-data = Open data path
|
||||||
|
|||||||
@@ -24,8 +24,9 @@ account-auth-server = Сервер аутентификации
|
|||||||
account-auth-button = Аутентифицировать
|
account-auth-button = Аутентифицировать
|
||||||
account-auth-save = Сохранить профиль
|
account-auth-save = Сохранить профиль
|
||||||
account-auth-hello = Привет,
|
account-auth-hello = Привет,
|
||||||
|
account-auth-current-server = Текущий сервер авторизации:
|
||||||
account-auth-logout = Выйти
|
account-auth-logout = Выйти
|
||||||
auth-current-login-name = Текущий профиль: {$login}
|
auth-current-login-name = Текущий профиль {$auth_server}: {$login}
|
||||||
auth-current-login-no-name = Профиль не выбран
|
auth-current-login-no-name = Профиль не выбран
|
||||||
|
|
||||||
auth-processing = Обработка запроса аутентификации...
|
auth-processing = Обработка запроса аутентификации...
|
||||||
@@ -37,6 +38,7 @@ auth-name-resolution-error = Не удалось разрешить адрес
|
|||||||
auth-secure-error = Не удалось подключиться к серверу по SSL. Проверьте сетевые настройки.
|
auth-secure-error = Не удалось подключиться к серверу по SSL. Проверьте сетевые настройки.
|
||||||
auth-config-read = Чтение конфигурации аутентификации...
|
auth-config-read = Чтение конфигурации аутентификации...
|
||||||
auth-try-auth-config = Попытка аутентификации с использованием сохраненной конфигурации.
|
auth-try-auth-config = Попытка аутентификации с использованием сохраненной конфигурации.
|
||||||
|
auth-try-auth-profile = Попытка аутентификации с использованием профиля
|
||||||
|
|
||||||
config-export-logs = Экспортировать логи
|
config-export-logs = Экспортировать логи
|
||||||
config-open-data = Открыть путь данных
|
config-open-data = Открыть путь данных
|
||||||
|
|||||||
@@ -34,7 +34,13 @@ public static class LauncherConVar
|
|||||||
"WizDen",
|
"WizDen",
|
||||||
[
|
[
|
||||||
"https://harpy.durenko.tatar/auth-api/",
|
"https://harpy.durenko.tatar/auth-api/",
|
||||||
|
"https://auth.spacestation14.com/",
|
||||||
"https://auth.fallback.spacestation14.com/",
|
"https://auth.fallback.spacestation14.com/",
|
||||||
|
]),
|
||||||
|
new AuthServerCredentials(
|
||||||
|
"SimpleStation",
|
||||||
|
[
|
||||||
|
"https://auth.simplestation.org/",
|
||||||
])
|
])
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
|
using Avalonia.Media;
|
||||||
using Nebula.Shared.Services;
|
using Nebula.Shared.Services;
|
||||||
|
|
||||||
namespace Nebula.Launcher.Models.Auth;
|
namespace Nebula.Launcher.Models.Auth;
|
||||||
|
|
||||||
public sealed record ProfileAuthCredentials(
|
public sealed record ProfileAuthCredentials(
|
||||||
AuthTokenCredentials Credentials,
|
AuthTokenCredentials Credentials,
|
||||||
|
string AuthName,
|
||||||
|
Color Color,
|
||||||
[property: JsonIgnore] ICommand OnSelect = default!,
|
[property: JsonIgnore] ICommand OnSelect = default!,
|
||||||
[property: JsonIgnore] ICommand OnDelete = default!);
|
[property: JsonIgnore] ICommand OnDelete = default!);
|
||||||
@@ -42,12 +42,12 @@ public partial class MainViewModel : ViewModelBase
|
|||||||
[ObservableProperty] private ListItemTemplate? _selectedListItem;
|
[ObservableProperty] private ListItemTemplate? _selectedListItem;
|
||||||
|
|
||||||
public bool IsLoggedIn => AccountInfoViewModel.Credentials is not null;
|
public bool IsLoggedIn => AccountInfoViewModel.Credentials is not null;
|
||||||
public string LoginName => AccountInfoViewModel.Credentials?.Login ?? string.Empty;
|
|
||||||
|
|
||||||
public string LoginText => LocalisationService.GetString("auth-current-login-name",
|
public string LoginText => LocalisationService.GetString("auth-current-login-name",
|
||||||
new Dictionary<string, object>
|
new Dictionary<string, object>
|
||||||
{
|
{
|
||||||
{ "login", LoginName }
|
{ "login", AccountInfoViewModel.Credentials?.Login ?? "" },
|
||||||
|
{ "auth_server", AccountInfoViewModel.CurrentAuthServerName}
|
||||||
});
|
});
|
||||||
|
|
||||||
[GenerateProperty] private LocalisationService LocalisationService { get; } // Не убирать! Без этой хуйни вся локализация идет в пизду!
|
[GenerateProperty] private LocalisationService LocalisationService { get; } // Не убирать! Без этой хуйни вся локализация идет в пизду!
|
||||||
|
|||||||
@@ -3,7 +3,10 @@ using System.Collections.Generic;
|
|||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Avalonia.Media;
|
||||||
using CommunityToolkit.Mvvm.ComponentModel;
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
using CommunityToolkit.Mvvm.Input;
|
using CommunityToolkit.Mvvm.Input;
|
||||||
using Nebula.Launcher.Models.Auth;
|
using Nebula.Launcher.Models.Auth;
|
||||||
@@ -23,20 +26,15 @@ namespace Nebula.Launcher.ViewModels.Pages;
|
|||||||
public partial class AccountInfoViewModel : ViewModelBase
|
public partial class AccountInfoViewModel : ViewModelBase
|
||||||
{
|
{
|
||||||
[ObservableProperty] private bool _authMenuExpand;
|
[ObservableProperty] private bool _authMenuExpand;
|
||||||
|
|
||||||
[ObservableProperty] private bool _authUrlConfigExpand;
|
[ObservableProperty] private bool _authUrlConfigExpand;
|
||||||
|
|
||||||
[ObservableProperty] private int _authViewSpan = 1;
|
[ObservableProperty] private int _authViewSpan = 1;
|
||||||
|
|
||||||
[ObservableProperty] private string _currentAuthServer = string.Empty;
|
[ObservableProperty] private string _currentAuthServer = string.Empty;
|
||||||
|
|
||||||
[ObservableProperty] private string _currentLogin = string.Empty;
|
[ObservableProperty] private string _currentLogin = string.Empty;
|
||||||
|
|
||||||
[ObservableProperty] private string _currentPassword = string.Empty;
|
[ObservableProperty] private string _currentPassword = string.Empty;
|
||||||
|
|
||||||
[ObservableProperty] private bool _isLogged;
|
[ObservableProperty] private bool _isLogged;
|
||||||
[ObservableProperty] private bool _doRetryAuth;
|
[ObservableProperty] private bool _doRetryAuth;
|
||||||
[ObservableProperty] private AuthTokenCredentials? _credentials;
|
[ObservableProperty] private AuthTokenCredentials? _credentials;
|
||||||
|
[ObservableProperty] private AuthServerCredentials _authItemSelect;
|
||||||
|
|
||||||
private bool _isProfilesEmpty;
|
private bool _isProfilesEmpty;
|
||||||
[GenerateProperty] private PopupMessageService PopupMessageService { get; } = default!;
|
[GenerateProperty] private PopupMessageService PopupMessageService { get; } = default!;
|
||||||
@@ -47,18 +45,22 @@ public partial class AccountInfoViewModel : ViewModelBase
|
|||||||
|
|
||||||
public ObservableCollection<ProfileAuthCredentials> Accounts { get; } = new();
|
public ObservableCollection<ProfileAuthCredentials> Accounts { get; } = new();
|
||||||
public ObservableCollection<AuthServerCredentials> AuthUrls { get; } = new();
|
public ObservableCollection<AuthServerCredentials> AuthUrls { get; } = new();
|
||||||
|
public string CurrentAuthServerName => GetServerAuthName(Credentials);
|
||||||
[ObservableProperty] private AuthServerCredentials _authItemSelect;
|
|
||||||
|
|
||||||
private ILogger _logger;
|
private ILogger _logger;
|
||||||
|
|
||||||
|
partial void OnCredentialsChanged(AuthTokenCredentials? value)
|
||||||
|
{
|
||||||
|
OnPropertyChanged(nameof(CurrentAuthServerName));
|
||||||
|
}
|
||||||
|
|
||||||
//Design think
|
//Design think
|
||||||
protected override void InitialiseInDesignMode()
|
protected override void InitialiseInDesignMode()
|
||||||
{
|
{
|
||||||
AddAccount(new AuthTokenCredentials(Guid.Empty, LoginToken.Empty, "Binka", ""));
|
|
||||||
AddAccount(new AuthTokenCredentials(Guid.Empty, LoginToken.Empty, "Binka", ""));
|
|
||||||
|
|
||||||
AuthUrls.Add(new AuthServerCredentials("Test",["example.com"]));
|
AuthUrls.Add(new AuthServerCredentials("Test",["example.com"]));
|
||||||
|
|
||||||
|
AddAccount(new AuthTokenCredentials(Guid.Empty, LoginToken.Empty, "Binka", "example.com"));
|
||||||
|
AddAccount(new AuthTokenCredentials(Guid.Empty, LoginToken.Empty, "Binka", ""));
|
||||||
}
|
}
|
||||||
|
|
||||||
//Real think
|
//Real think
|
||||||
@@ -225,6 +227,13 @@ public partial class AccountInfoViewModel : ViewModelBase
|
|||||||
{
|
{
|
||||||
IsLogged = false;
|
IsLogged = false;
|
||||||
Credentials = null;
|
Credentials = null;
|
||||||
|
CurrentAuthServer = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetServerAuthName(AuthTokenCredentials? credentials)
|
||||||
|
{
|
||||||
|
if (credentials is null) return "";
|
||||||
|
return AuthUrls.FirstOrDefault(p => p.Servers.Contains(credentials.AuthServer))?.Name ?? "CustomAuth";
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateAuthMenu()
|
private void UpdateAuthMenu()
|
||||||
@@ -239,9 +248,13 @@ public partial class AccountInfoViewModel : ViewModelBase
|
|||||||
{
|
{
|
||||||
var onDelete = new DelegateCommand<ProfileAuthCredentials>(OnDeleteProfile);
|
var onDelete = new DelegateCommand<ProfileAuthCredentials>(OnDeleteProfile);
|
||||||
var onSelect = new DelegateCommand<ProfileAuthCredentials>(AuthByProfile);
|
var onSelect = new DelegateCommand<ProfileAuthCredentials>(AuthByProfile);
|
||||||
|
|
||||||
|
var serverName = GetServerAuthName(credentials);
|
||||||
|
|
||||||
var alpm = new ProfileAuthCredentials(
|
var alpm = new ProfileAuthCredentials(
|
||||||
credentials,
|
credentials,
|
||||||
|
serverName,
|
||||||
|
ColorUtils.GetColorFromString(credentials.AuthServer),
|
||||||
onSelect,
|
onSelect,
|
||||||
onDelete);
|
onDelete);
|
||||||
|
|
||||||
@@ -257,16 +270,18 @@ public partial class AccountInfoViewModel : ViewModelBase
|
|||||||
message.InfoText = LocalisationService.GetString("auth-config-read");
|
message.InfoText = LocalisationService.GetString("auth-config-read");
|
||||||
message.IsInfoClosable = false;
|
message.IsInfoClosable = false;
|
||||||
PopupMessageService.Popup(message);
|
PopupMessageService.Popup(message);
|
||||||
|
|
||||||
|
AuthUrls.Clear();
|
||||||
|
var authUrls = ConfigurationService.GetConfigValue(LauncherConVar.AuthServers)!;
|
||||||
|
foreach (var url in authUrls) AuthUrls.Add(url);
|
||||||
|
if(authUrls.Length > 0) AuthItemSelect = authUrls[0];
|
||||||
|
|
||||||
foreach (var profile in
|
foreach (var profile in
|
||||||
ConfigurationService.GetConfigValue(LauncherConVar.AuthProfiles)!)
|
ConfigurationService.GetConfigValue(LauncherConVar.AuthProfiles)!)
|
||||||
AddAccount(profile);
|
AddAccount(profile);
|
||||||
|
|
||||||
if (Accounts.Count == 0) UpdateAuthMenu();
|
if (Accounts.Count == 0) UpdateAuthMenu();
|
||||||
|
|
||||||
AuthUrls.Clear();
|
|
||||||
var authUrls = ConfigurationService.GetConfigValue(LauncherConVar.AuthServers)!;
|
|
||||||
foreach (var url in authUrls) AuthUrls.Add(url);
|
|
||||||
if(authUrls.Length > 0) AuthItemSelect = authUrls[0];
|
|
||||||
message.Dispose();
|
message.Dispose();
|
||||||
|
|
||||||
DoCurrentAuth();
|
DoCurrentAuth();
|
||||||
@@ -347,4 +362,18 @@ public partial class AccountInfoViewModel : ViewModelBase
|
|||||||
ConfigurationService.SetConfigValue(LauncherConVar.AuthProfiles,
|
ConfigurationService.SetConfigValue(LauncherConVar.AuthProfiles,
|
||||||
Accounts.Select(a => a.Credentials).ToArray());
|
Accounts.Select(a => a.Credentials).ToArray());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ColorUtils
|
||||||
|
{
|
||||||
|
public static Color GetColorFromString(string input)
|
||||||
|
{
|
||||||
|
var hash = MD5.HashData(Encoding.UTF8.GetBytes(input));
|
||||||
|
|
||||||
|
var r = byte.Clamp(hash[0], 10, 200);
|
||||||
|
var g = byte.Clamp(hash[1], 10, 100);
|
||||||
|
var b = byte.Clamp(hash[2], 10, 100);
|
||||||
|
|
||||||
|
return Color.FromArgb(Byte.MaxValue, r, g, b);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
<UserControl
|
<UserControl
|
||||||
d:DesignHeight="450"
|
d:DesignHeight="450"
|
||||||
d:DesignWidth="800"
|
d:DesignWidth="1000"
|
||||||
mc:Ignorable="d"
|
mc:Ignorable="d"
|
||||||
x:Class="Nebula.Launcher.Views.Pages.AccountInfoView"
|
x:Class="Nebula.Launcher.Views.Pages.AccountInfoView"
|
||||||
x:DataType="pages:AccountInfoViewModel"
|
x:DataType="pages:AccountInfoViewModel"
|
||||||
@@ -39,39 +39,56 @@
|
|||||||
Padding="0">
|
Padding="0">
|
||||||
<ItemsControl.ItemTemplate>
|
<ItemsControl.ItemTemplate>
|
||||||
<DataTemplate DataType="{x:Type auth:ProfileAuthCredentials}">
|
<DataTemplate DataType="{x:Type auth:ProfileAuthCredentials}">
|
||||||
<Border
|
<Grid ColumnDefinitions="4*,*">
|
||||||
BoxShadow="0 1 15 -2 #121212"
|
<Border
|
||||||
CornerRadius="0,10,0,10"
|
BoxShadow="0 1 15 -2 #121212"
|
||||||
Margin="5,5,5,0"
|
CornerRadius="0,10,0,10"
|
||||||
VerticalAlignment="Center">
|
Margin="5,5,5,0">
|
||||||
<Border.Background>
|
<Border.Background>
|
||||||
<LinearGradientBrush EndPoint="50%,100%" StartPoint="50%,0%">
|
<LinearGradientBrush EndPoint="100%,50%" StartPoint="20%,50%">
|
||||||
<GradientStop Color="#292222" Offset="0.0" />
|
<GradientStop Color="{Binding Color}" Offset="0.0" />
|
||||||
<GradientStop Color="#222222" Offset="1.0" />
|
<GradientStop Color="#222222" Offset="1.0" />
|
||||||
</LinearGradientBrush>
|
</LinearGradientBrush>
|
||||||
</Border.Background>
|
</Border.Background>
|
||||||
<Panel>
|
<Label>
|
||||||
<StackPanel Margin="10,5,5,5" Orientation="Horizontal">
|
<TextBlock Text="{Binding AuthName}" Margin="5"/>
|
||||||
|
</Label>
|
||||||
|
</Border>
|
||||||
|
<Border Grid.Column="0"
|
||||||
|
CornerRadius="0,10,0,10"
|
||||||
|
Margin="5,5,5,0">
|
||||||
|
<Border.Background>
|
||||||
|
<LinearGradientBrush EndPoint="100%,50%" StartPoint="20%,50%">
|
||||||
|
<GradientStop Color="#aa222222" Offset="0.0" />
|
||||||
|
<GradientStop Color="#222222" Offset="0.4" />
|
||||||
|
</LinearGradientBrush>
|
||||||
|
</Border.Background>
|
||||||
|
<Button
|
||||||
|
HorizontalAlignment="Stretch"
|
||||||
|
Command="{Binding OnSelect}">
|
||||||
<Label>
|
<Label>
|
||||||
<TextBlock Text="{Binding Credentials.Login}" />
|
<TextBlock Text="{Binding Credentials.Login}" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="0,0,5,0"/>
|
||||||
</Label>
|
</Label>
|
||||||
</StackPanel>
|
</Button>
|
||||||
<StackPanel HorizontalAlignment="Right" Orientation="Horizontal">
|
</Border>
|
||||||
<Button
|
<Border
|
||||||
Command="{Binding OnSelect}"
|
BoxShadow="0 1 15 -2 #121212"
|
||||||
CornerRadius="0,0,0,10"
|
CornerRadius="0,10,0,10"
|
||||||
Padding="5">
|
Margin="0,5,5,0" Grid.Column="1" Padding="0">
|
||||||
<customControls:LocalizedLabel LocalId="account-profile-select"/>
|
<Border.Background>
|
||||||
</Button>
|
<LinearGradientBrush EndPoint="100%,50%" StartPoint="20%,50%">
|
||||||
<Button
|
<GradientStop Color="#292222" Offset="1.0" />
|
||||||
Command="{Binding OnDelete}"
|
<GradientStop Color="#222222" Offset="1.0" />
|
||||||
CornerRadius="0,10,0,0"
|
</LinearGradientBrush>
|
||||||
Padding="5">
|
</Border.Background>
|
||||||
<customControls:LocalizedLabel LocalId="account-profile-delete"/>
|
<Button Command="{Binding OnDelete}" CornerRadius="0,10,0,10" HorizontalAlignment="Stretch">
|
||||||
</Button>
|
<Svg
|
||||||
</StackPanel>
|
Height="15"
|
||||||
</Panel>
|
Path="/Assets/svg/delete.svg"
|
||||||
</Border>
|
Width="15" />
|
||||||
|
</Button>
|
||||||
|
</Border>
|
||||||
|
</Grid>
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
</ItemsControl.ItemTemplate>
|
</ItemsControl.ItemTemplate>
|
||||||
</ItemsControl>
|
</ItemsControl>
|
||||||
@@ -169,9 +186,15 @@
|
|||||||
Margin="0,0,0,20"
|
Margin="0,0,0,20"
|
||||||
Path="/Assets/svg/user.svg" />
|
Path="/Assets/svg/user.svg" />
|
||||||
<Label>
|
<Label>
|
||||||
<StackPanel HorizontalAlignment="Center" Orientation="Horizontal">
|
<StackPanel>
|
||||||
<customControls:LocalizedLabel LocalId="account-auth-hello"/>
|
<StackPanel HorizontalAlignment="Center" Orientation="Horizontal" Spacing="5">
|
||||||
<TextBlock Text="{Binding CurrentLogin}" />
|
<customControls:LocalizedLabel LocalId="account-auth-hello"/>
|
||||||
|
<TextBlock Text="{Binding CurrentLogin}" />
|
||||||
|
</StackPanel>
|
||||||
|
<StackPanel HorizontalAlignment="Center" Orientation="Horizontal" Spacing="5">
|
||||||
|
<customControls:LocalizedLabel LocalId="account-auth-current-server"/>
|
||||||
|
<TextBlock Text="{Binding CurrentAuthServerName}" />
|
||||||
|
</StackPanel>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</Label>
|
</Label>
|
||||||
<StackPanel
|
<StackPanel
|
||||||
|
|||||||
Reference in New Issue
Block a user