Skip to content

Commit

Permalink
Revert "EventfulUserKeysService emits keys progress to MainLayout"
Browse files Browse the repository at this point in the history
This reverts commit 36b41fd.
  • Loading branch information
Jack-Edwards committed Jan 12, 2025
1 parent 36b41fd commit 1add12c
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,4 @@ namespace Crypter.Common.Client.Interfaces.Services;
public interface IEventfulUserKeysService
{
event EventHandler<EmitRecoveryKeyEventArgs> EmitRecoveryKeyEventHandler;
event EventHandler PrepareUserKeysBeginEventHandler;
event EventHandler PrepareUserKeysEndEventHandler;
}
26 changes: 0 additions & 26 deletions Crypter.Common.Client/Services/EventfulUserKeysService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ public sealed class EventfulUserKeysService : UserKeysService, IEventfulUserKeys
{
private readonly IUserSessionService _userSessionService;
private EventHandler<EmitRecoveryKeyEventArgs>? _emitRecoveryKeyEventHandler;
private event EventHandler? _prepareUserKeysBeginEventHandler;
private event EventHandler? _prepareUserKeysEndEventHandler;

public EventfulUserKeysService(ICrypterApiClient crypterApiClient, ICryptoProvider cryptoProvider, IUserPasswordService userPasswordService, IUserKeysRepository userKeysRepository, IUserSessionService userSessionService)
: base(crypterApiClient, cryptoProvider, userPasswordService, userKeysRepository)
Expand All @@ -64,15 +62,13 @@ private async void InitializeAsync(object? _, UserSessionServiceInitializedEvent
private async void HandleUserLoginAsync(object? _, UserLoggedInEventArgs args)
{
await UserPasswordService.DeriveUserCredentialKeyAsync(args.Username, args.Password, UserPasswordService.CurrentPasswordVersion)
.IfSomeAsync(_ => HandlePrepareUserKeysBeginEvent())
.BindAsync(async credentialKey => await GetOrCreateMasterKeyAsync(args.VersionedPassword, credentialKey)
.BindAsync(x => new { CredentialKey = credentialKey, x.MasterKey, x.NewRecoveryKey }))
.BindAsync(async carryData => await GetOrCreateKeyPairAsync(carryData.MasterKey)
.BindAsync(x => new { carryData.CredentialKey, carryData.MasterKey, x.PrivateKey, carryData.NewRecoveryKey }))
.IfSomeAsync(async carryData =>
{
await StoreSecretKeysAsync(carryData.MasterKey, carryData.PrivateKey, args.RememberUser);
HandlePrepareUserKeysEndEvent();
await carryData.NewRecoveryKey
.IfSome(HandleEmitRecoveryKeyEvent)
.IfNoneAsync(async () =>
Expand All @@ -89,12 +85,6 @@ await DeriveRecoveryKeyAsync(carryData.MasterKey, args.VersionedPassword)
private void HandleEmitRecoveryKeyEvent(RecoveryKey recoveryKey) =>
_emitRecoveryKeyEventHandler?.Invoke(this, new EmitRecoveryKeyEventArgs(recoveryKey));

private void HandlePrepareUserKeysBeginEvent() =>
_prepareUserKeysBeginEventHandler?.Invoke(this, EventArgs.Empty);

private void HandlePrepareUserKeysEndEvent() =>
_prepareUserKeysEndEventHandler?.Invoke(this, EventArgs.Empty);

public event EventHandler<EmitRecoveryKeyEventArgs> EmitRecoveryKeyEventHandler
{
add => _emitRecoveryKeyEventHandler =
Expand All @@ -103,22 +93,6 @@ public event EventHandler<EmitRecoveryKeyEventArgs> EmitRecoveryKeyEventHandler
(EventHandler<EmitRecoveryKeyEventArgs>?)Delegate.Remove(_emitRecoveryKeyEventHandler, value);
}

public event EventHandler PrepareUserKeysBeginEventHandler
{
add => _prepareUserKeysBeginEventHandler =
(EventHandler)Delegate.Combine(_prepareUserKeysBeginEventHandler, value);
remove => _prepareUserKeysBeginEventHandler =
(EventHandler?)Delegate.Remove(_prepareUserKeysBeginEventHandler, value);
}

public event EventHandler PrepareUserKeysEndEventHandler
{
add => _prepareUserKeysEndEventHandler =
(EventHandler)Delegate.Combine(_prepareUserKeysEndEventHandler, value);
remove => _prepareUserKeysEndEventHandler =
(EventHandler?)Delegate.Remove(_prepareUserKeysEndEventHandler, value);
}

private void Recycle(object? _, EventArgs __)
{
MasterKey = Maybe<byte[]>.None;
Expand Down
1 change: 0 additions & 1 deletion Crypter.Web/Client/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@
.AddSingleton<IUserContactsService, UserContactsService>()
.AddSingleton<IUserPasswordService, UserPasswordService>()
.AddSingleton<IUserRecoveryService, UserRecoveryService>()
.AddSingleton<IEventfulUserKeysService, EventfulUserKeysService>()
.AddSingleton<IUserKeysService, UserKeysService>()
.AddSingleton<IUserProfileSettingsService, UserProfileSettingsService>()
.AddSingleton<IUserContactInfoSettingsService, UserContactInfoSettingsService>()
Expand Down
12 changes: 0 additions & 12 deletions Crypter.Web/Shared/MainLayout.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,6 @@ protected override async Task OnInitializedAsync()
ServicesInitialized = true;
}

private void ShowUserKeysProgressModal(object? _, EventArgs __)
{
SpinnerModal.Open("Preparing Secret Keys",
"Please wait while your secret keys are being prepared.",
Maybe<EventCallback>.None);
}

private async void CloseUserKeysProgressModal(object? _, EventArgs __)
{
await SpinnerModal.CloseAsync();
}

private void HandleRecoveryKeyCreatedEvent(object? _, EmitRecoveryKeyEventArgs args)
{
RecoveryKeyModal.Open(args.RecoveryKey);
Expand Down
3 changes: 2 additions & 1 deletion Crypter.Web/Shared/Modal/SpinnerModal.razor.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2025 Crypter File Transfer
* Copyright (C) 2024 Crypter File Transfer
*
* This file is part of the Crypter file transfer project.
*
Expand All @@ -24,6 +24,7 @@
* Contact the current copyright holder to discuss commercial license options.
*/

using System;
using System.Threading.Tasks;
using Crypter.Web.Shared.Modal.Template;
using EasyMonads;
Expand Down

0 comments on commit 1add12c

Please sign in to comment.