1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-12 13:28:33 +00:00

Account management - Final tweaks

This commit is contained in:
RobertBeekman 2024-02-13 21:55:09 +01:00
parent a2fe5d5d08
commit 38a1318170
4 changed files with 42 additions and 32 deletions

View File

@ -18,7 +18,7 @@ public sealed class Layer : RenderProfileElement
{
private const string BROKEN_STATE_BRUSH_NOT_FOUND = "Failed to load layer brush, ensure the plugin is enabled";
private const string BROKEN_STATE_INIT_FAILED = "Failed to initialize layer brush";
private readonly List<Layer> _renderCopies = new();
private LayerGeneralProperties _general = new();
private LayerTransformProperties _transform = new();
@ -735,6 +735,9 @@ public sealed class Layer : RenderProfileElement
if (Disposed)
throw new ObjectDisposedException("Layer");
if (_leds.Contains(led))
return;
_leds.Add(led);
CalculateRenderProperties();
}
@ -761,7 +764,9 @@ public sealed class Layer : RenderProfileElement
if (Disposed)
throw new ObjectDisposedException("Layer");
_leds.Remove(led);
if (!_leds.Remove(led))
return;
CalculateRenderProperties();
}
@ -773,6 +778,9 @@ public sealed class Layer : RenderProfileElement
if (Disposed)
throw new ObjectDisposedException("Layer");
if (!_leds.Any())
return;
_leds.Clear();
CalculateRenderProperties();
}
@ -790,7 +798,7 @@ public sealed class Layer : RenderProfileElement
{
ArtemisLed? match = availableLeds.FirstOrDefault(a => a.Device.Identifier == ledEntity.DeviceIdentifier &&
a.RgbLed.Id.ToString() == ledEntity.LedName);
if (match != null)
if (match != null && !leds.Contains(match))
leds.Add(match);
else
_missingLeds.Add(ledEntity);

View File

@ -5,6 +5,7 @@
xmlns:settings="clr-namespace:Artemis.UI.Screens.Settings"
xmlns:asyncImageLoader="clr-namespace:AsyncImageLoader;assembly=AsyncImageLoader.Avalonia"
xmlns:loaders="clr-namespace:AsyncImageLoader.Loaders;assembly=AsyncImageLoader.Avalonia"
xmlns:controls="clr-namespace:FluentAvalonia.UI.Controls;assembly=FluentAvalonia"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="800"
x:Class="Artemis.UI.Screens.Settings.AccountTabView"
x:DataType="settings:AccountTabViewModel">
@ -34,9 +35,9 @@
</TextBlock>
<Button HorizontalAlignment="Center" Command="{CompiledBinding Login}" Margin="0 25 0 0">Login</Button>
</StackPanel>
<ScrollViewer IsVisible="{CompiledBinding IsLoggedIn^}" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto">
<StackPanel>
<StackPanel Margin="15" MaxWidth="1000">
<Grid RowDefinitions="*,*" ColumnDefinitions="Auto,*" VerticalAlignment="Top">
<Border Grid.Row="0" Grid.Column="0" Grid.RowSpan="2" VerticalAlignment="Top" CornerRadius="92" Width="92" Height="92" Margin="0 0 15 0" ClipToBounds="True">
<asyncImageLoader:AdvancedImage Source="{CompiledBinding AvatarUrl}">
@ -45,7 +46,7 @@
</asyncImageLoader:AdvancedImage.Loader>
</asyncImageLoader:AdvancedImage>
</Border>
<TextBlock Grid.Row="0" Grid.Column="1" Padding="0" VerticalAlignment="Bottom" Text="{CompiledBinding Name}" />
<TextBlock Grid.Row="0" Grid.Column="1" Padding="0" VerticalAlignment="Bottom" Text="{CompiledBinding Name}" Classes="h3 no-margin"/>
<TextBlock Classes="subtitle" Grid.Column="1" Grid.Row="1" Padding="0" VerticalAlignment="Top" Text="{CompiledBinding Email}" />
</Grid>
@ -54,11 +55,27 @@
</TextBlock>
<Border Classes="card" VerticalAlignment="Stretch" Margin="0,0,5,0">
<StackPanel>
<Grid RowDefinitions="*,*" ColumnDefinitions="*,Auto" IsVisible="{CompiledBinding CanChangePassword}">
<StackPanel Grid.Column="0" VerticalAlignment="Top">
<TextBlock>
Credentials
</TextBlock>
</StackPanel>
<StackPanel Grid.Row="0" Grid.Column="1" VerticalAlignment="Center" Spacing="10">
<Button Width="150" Content="Change email" Command="{CompiledBinding ChangeEmailAddress}" />
<Button Width="150" Content="Change password" Command="{CompiledBinding ChangePasswordAddress}" />
</StackPanel>
</Grid>
<Border Classes="card-separator" IsVisible="{CompiledBinding CanChangePassword}"/>
<Grid RowDefinitions="*,*" ColumnDefinitions="*,Auto">
<StackPanel Grid.Column="0" VerticalAlignment="Center">
<TextBlock>
Change avatar
</TextBlock>
<TextBlock Classes="subtitle">
Quite pointless currently, but in the future your avatar will be visible in the workshop.
</TextBlock>
</StackPanel>
<StackPanel Grid.Row="0" Grid.Column="1" VerticalAlignment="Center">
<Button Width="150" Content="Choose image" Command="{CompiledBinding ChangeAvatar}" />
@ -66,37 +83,13 @@
</Grid>
<Border Classes="card-separator" />
<Grid RowDefinitions="*,*" ColumnDefinitions="*,Auto">
<StackPanel Grid.Column="0" VerticalAlignment="Center">
<TextBlock>
Email address
</TextBlock>
</StackPanel>
<StackPanel Grid.Row="0" Grid.Column="1" VerticalAlignment="Center">
<Button Width="150" Content=" Change email" Command="{CompiledBinding ChangeEmailAddress}" />
</StackPanel>
</Grid>
<Border Classes="card-separator" />
<Grid RowDefinitions="*,*" ColumnDefinitions="*,Auto">
<StackPanel Grid.Column="0" VerticalAlignment="Center">
<TextBlock>
Password
</TextBlock>
</StackPanel>
<StackPanel Grid.Row="0" Grid.Column="1" VerticalAlignment="Center">
<Button Width="150" Content="Change password" Command="{CompiledBinding ChangePasswordAddress}" />
</StackPanel>
</Grid>
<Border Classes="card-separator" />
<Grid RowDefinitions="*,*" ColumnDefinitions="*,Auto">
<StackPanel Grid.Column="0" VerticalAlignment="Center">
<TextBlock>
Remove account
</TextBlock>
<TextBlock Classes="subtitle">
Permanently remove your account, this cannot be undone
Permanently remove your account, this cannot be undone.
</TextBlock>
</StackPanel>
<StackPanel Grid.Row="0" Grid.Column="1" VerticalAlignment="Center">

View File

@ -3,6 +3,7 @@ using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Threading;
using System.Threading.Tasks;
using Artemis.UI.Screens.Settings.Account;
@ -12,6 +13,7 @@ using Artemis.UI.Shared.Services;
using Artemis.WebClient.Workshop;
using Artemis.WebClient.Workshop.Handlers.UploadHandlers;
using Artemis.WebClient.Workshop.Services;
using IdentityModel;
using PropertyChanged.SourceGenerator;
using ReactiveUI;
@ -22,6 +24,7 @@ public partial class AccountTabViewModel : RoutableScreen
private readonly IWindowService _windowService;
private readonly IAuthenticationService _authenticationService;
private readonly IUserManagementService _userManagementService;
private ObservableAsPropertyHelper<bool>? _canChangePassword;
[Notify(Setter.Private)] private string? _name;
[Notify(Setter.Private)] private string? _email;
@ -37,9 +40,15 @@ public partial class AccountTabViewModel : RoutableScreen
DisplayName = "Account";
IsLoggedIn = _authenticationService.IsLoggedIn;
this.WhenActivated(d =>
{
_canChangePassword = _authenticationService.GetClaim(JwtClaimTypes.AuthenticationMethod).Select(c => c?.Value == "pwd").ToProperty(this, vm => vm.CanChangePassword);
_canChangePassword.DisposeWith(d);
});
this.WhenActivated(d => _authenticationService.IsLoggedIn.Subscribe(_ => LoadCurrentUser()).DisposeWith(d));
}
public bool CanChangePassword => _canChangePassword?.Value ?? false;
public IObservable<bool> IsLoggedIn { get; }
public async Task Login()

View File

@ -123,7 +123,7 @@ internal class AuthenticationService : CorePropertyChanged, IAuthenticationServi
public IObservable<Claim?> GetClaim(string type)
{
return _claims.Connect()
.Filter(c => c.Type == JwtClaimTypes.Email)
.Filter(c => c.Type == type)
.ToCollection()
.Select(f => f.FirstOrDefault());
}