Migrate ActivityLogEntryPoint.OnUserPasswordChanged to IEventConsumer

This commit is contained in:
Patrick Barron 2020-08-13 21:07:08 -04:00
parent 737a86d0cb
commit a1ecafb40d
3 changed files with 61 additions and 14 deletions

View File

@ -63,7 +63,6 @@ namespace Emby.Server.Implementations.Activity
_sessionManager.AuthenticationSucceeded += OnAuthenticationSucceeded;
_sessionManager.SessionEnded += OnSessionEnded;
_userManager.OnUserPasswordChanged += OnUserPasswordChanged;
_userManager.OnUserLockedOut += OnUserLockedOut;
return Task.CompletedTask;
@ -145,18 +144,6 @@ namespace Emby.Server.Implementations.Activity
}).ConfigureAwait(false);
}
private async void OnUserPasswordChanged(object sender, GenericEventArgs<User> e)
{
await CreateLogEntry(new ActivityLog(
string.Format(
CultureInfo.InvariantCulture,
_localization.GetLocalizedString("UserPasswordChangedWithName"),
e.Argument.Username),
"UserPasswordChanged",
e.Argument.Id))
.ConfigureAwait(false);
}
private async void OnSessionStarted(object sender, SessionEventArgs e)
{
var session = e.SessionInfo;
@ -265,7 +252,6 @@ namespace Emby.Server.Implementations.Activity
_sessionManager.AuthenticationSucceeded -= OnAuthenticationSucceeded;
_sessionManager.SessionEnded -= OnSessionEnded;
_userManager.OnUserPasswordChanged -= OnUserPasswordChanged;
_userManager.OnUserLockedOut -= OnUserLockedOut;
}
}

View File

@ -0,0 +1,18 @@
using Jellyfin.Data.Entities;
namespace Jellyfin.Data.Events.Users
{
/// <summary>
/// An event that occurs when a user's password has changed.
/// </summary>
public class UserPasswordChangedEventArgs : GenericEventArgs<User>
{
/// <summary>
/// Initializes a new instance of the <see cref="UserPasswordChangedEventArgs"/> class.
/// </summary>
/// <param name="arg">The user.</param>
public UserPasswordChangedEventArgs(User arg) : base(arg)
{
}
}
}

View File

@ -0,0 +1,43 @@
using System.Globalization;
using System.Threading.Tasks;
using Jellyfin.Data.Entities;
using Jellyfin.Data.Events.Users;
using MediaBrowser.Controller.Events;
using MediaBrowser.Model.Activity;
using MediaBrowser.Model.Globalization;
namespace Jellyfin.Server.Implementations.Events.Consumers.Users
{
/// <summary>
/// Creates an entry in the activity log when a user's password is changed.
/// </summary>
public class UserPasswordChangedLogger : IEventConsumer<UserPasswordChangedEventArgs>
{
private readonly ILocalizationManager _localizationManager;
private readonly IActivityManager _activityManager;
/// <summary>
/// Initializes a new instance of the <see cref="UserPasswordChangedLogger"/> class.
/// </summary>
/// <param name="localizationManager">The localization manager.</param>
/// <param name="activityManager">The activity manager.</param>
public UserPasswordChangedLogger(ILocalizationManager localizationManager, IActivityManager activityManager)
{
_localizationManager = localizationManager;
_activityManager = activityManager;
}
/// <inheritdoc />
public async Task OnEvent(UserPasswordChangedEventArgs eventArgs)
{
await _activityManager.CreateAsync(new ActivityLog(
string.Format(
CultureInfo.InvariantCulture,
_localizationManager.GetLocalizedString("UserPasswordChangedWithName"),
eventArgs.Argument.Username),
"UserPasswordChanged",
eventArgs.Argument.Id))
.ConfigureAwait(false);
}
}
}