Settings - Added account management

This commit is contained in:
RobertBeekman committed 2024-02-08 20:58:16 +01:00
1 parent 3952a268d1
commit a2fe5d5d08
42 files changed
+681 -30

No files matched your search

@@ -34,8 +34,8 @@
Name="UserMenu">
<Ellipse.ContextFlyout>
<Flyout>
<Grid ColumnDefinitions="Auto,*" RowDefinitions="*,*,*" MinWidth="300">
<Ellipse Grid.Column="0" Grid.RowSpan="3" Height="50" Width="50" Margin="0 0 8 0" VerticalAlignment="Top">
<Grid ColumnDefinitions="Auto,*" RowDefinitions="*,*,*,*" MinWidth="300">
<Ellipse Grid.Column="0" Grid.RowSpan="4" Height="50" Width="50" Margin="0 0 8 0" VerticalAlignment="Top">
<Ellipse.Fill>
<ImageBrush asyncImageLoader:ImageBrushLoader.Source="{CompiledBinding AvatarUrl}" />
</Ellipse.Fill>
@@ -46,10 +46,20 @@
IsVisible="{CompiledBinding AllowLogout}"
Grid.Column="1"
Grid.Row="2"
Margin="-8 4 0 0"
Padding="6 4"
Click="Signout_OnClick">
Sign out
</controls:HyperlinkButton>
<controls:HyperlinkButton
IsVisible="{CompiledBinding AllowLogout}"
Grid.Column="1"
Grid.Row="3"
Margin="-8 0 0 0"
Padding="6 4"
Click="Button_OnClick">
Sign out
Click="Manage_OnClick">
Manage account
</controls:HyperlinkButton>
</Grid>
</Flyout>
@@ -13,9 +13,15 @@ public partial class CurrentUserView : ReactiveUserControl<CurrentUserViewModel>
InitializeComponent();
}
private void Button_OnClick(object? sender, RoutedEventArgs e)
private void Signout_OnClick(object? sender, RoutedEventArgs e)
{
UserMenu.ContextFlyout?.Hide();
ViewModel?.Logout();
}
private void Manage_OnClick(object? sender, RoutedEventArgs e)
{
UserMenu.ContextFlyout?.Hide();
ViewModel?.ManageAccount();
}
}
@@ -6,6 +6,7 @@ using System.Reactive.Disposables;
using System.Threading;
using System.Threading.Tasks;
using Artemis.UI.Shared;
using Artemis.UI.Shared.Routing;
using Artemis.UI.Shared.Services;
using Artemis.WebClient.Workshop;
using Artemis.WebClient.Workshop.Services;
@@ -23,6 +24,7 @@ public partial class CurrentUserViewModel : ActivatableViewModelBase
private readonly ObservableAsPropertyHelper<bool> _isAnonymous;
private readonly ILogger _logger;
private readonly IWindowService _windowService;
private readonly IRouter _router;
[Notify] private bool _allowLogout = true;
[Notify(Setter.Private)] private Bitmap? _avatar;
[Notify(Setter.Private)] private string? _email;
@@ -31,11 +33,12 @@ public partial class CurrentUserViewModel : ActivatableViewModelBase
[Notify(Setter.Private)] private string? _userId;
[Notify(Setter.Private)] private string? _avatarUrl;
public CurrentUserViewModel(ILogger logger, IAuthenticationService authenticationService, IWindowService windowService)
public CurrentUserViewModel(ILogger logger, IAuthenticationService authenticationService, IWindowService windowService, IRouter router)
{
_logger = logger;
_authenticationService = authenticationService;
_windowService = windowService;
_router = router;
Login = ReactiveCommand.CreateFromTask(ExecuteLogin);
_isAnonymous = this.WhenAnyValue(vm => vm.Loading, vm => vm.Name, (l, n) => l || n == null).ToProperty(this, vm => vm.IsAnonymous);
@@ -92,4 +95,9 @@ public partial class CurrentUserViewModel : ActivatableViewModelBase
Email = _authenticationService.Claims.FirstOrDefault(c => c.Type == "email")?.Value;
AvatarUrl = $"{WorkshopConstants.AUTHORITY_URL}/user/avatar/{UserId}";
}
public void ManageAccount()
{
_router.Navigate("settings/account");
}
}
@@ -8,6 +8,7 @@ using Artemis.UI.Shared.Services.Builders;
using Artemis.UI.Shared.Utilities;
using Artemis.WebClient.Workshop;
using Artemis.WebClient.Workshop.Handlers.InstallationHandlers;
using Artemis.WebClient.Workshop.Models;
using Artemis.WebClient.Workshop.Services;
using Humanizer;
using ReactiveUI;
@@ -7,6 +7,7 @@ using Artemis.Core.Services;
using Artemis.UI.DryIoc.Factories;
using Artemis.UI.Screens.SurfaceEditor;
using Artemis.UI.Shared;
using Artemis.WebClient.Workshop.Models;
using Artemis.WebClient.Workshop.Providers;
using Artemis.WebClient.Workshop.Services;
using ReactiveUI;
@@ -12,6 +12,7 @@ using Artemis.UI.Screens.Workshop.Parameters;
using Artemis.UI.Shared.Routing;
using Artemis.UI.Shared.Services;
using Artemis.WebClient.Workshop;
using Artemis.WebClient.Workshop.Models;
using Artemis.WebClient.Workshop.Services;
using PropertyChanged.SourceGenerator;
using StrawberryShake;
@@ -213,7 +213,7 @@ public partial class SubmissionDetailViewModel : RoutableScreen<WorkshopDetailPa
{
using MemoryStream stream = new();
EntrySpecificationsViewModel.IconBitmap.Save(stream);
ImageUploadResult imageResult = await _workshopService.SetEntryIcon(Entry.Id, stream, cancellationToken);
ApiResult imageResult = await _workshopService.SetEntryIcon(Entry.Id, stream, cancellationToken);
if (!imageResult.IsSuccess)
throw new ArtemisWorkshopException("Failed to upload image. " + imageResult.Message);
}
@@ -7,6 +7,7 @@ using Artemis.UI.Shared.Routing;
using Artemis.UI.Shared.Services;
using Artemis.WebClient.Workshop;
using Artemis.WebClient.Workshop.Handlers.InstallationHandlers;
using Artemis.WebClient.Workshop.Models;
using Artemis.WebClient.Workshop.Services;
using PropertyChanged.SourceGenerator;
using ReactiveUI;
@@ -4,6 +4,7 @@ using System.Collections.ObjectModel;
using System.Reactive;
using System.Reactive.Linq;
using Artemis.UI.Shared.Routing;
using Artemis.WebClient.Workshop.Models;
using Artemis.WebClient.Workshop.Services;
using DynamicData;
using DynamicData.Binding;
@@ -129,11 +129,11 @@ public partial class UploadStepViewModel : SubmissionViewModel
return entryId;
}
private async Task TryImageUpload(Func<Task<ImageUploadResult>> action)
private async Task TryImageUpload(Func<Task<ApiResult>> action)
{
try
{
ImageUploadResult result = await action();
ApiResult result = await action();
if (!result.IsSuccess)
throw new ArtemisWorkshopException(result.Message);
}