The Free Software Media System - Server Backend & API
Migrate ActivityLogEntryPoint.OnAuthenticationSucceeded to IEventConsumer
Patrick Barronf4275adfcb4c
diff --git a/Emby.Server.Implementations/Activity/ActivityLogEntryPoint.cs b/Emby.Server.Implementations/Activity/ActivityLogEntryPoint.csindex 8279503ec8..40fc7d8907 100644--- a/Emby.Server.Implementations/Activity/ActivityLogEntryPoint.cs+++ b/Emby.Server.Implementations/Activity/ActivityLogEntryPoint.cs@@ -2,10 +2,8 @@ using System;using System.Globalization;using System.Threading.Tasks;using Jellyfin.Data.Entities;-using Jellyfin.Data.Events;using MediaBrowser.Common.Plugins;using MediaBrowser.Common.Updates;-using MediaBrowser.Controller.Authentication;using MediaBrowser.Controller.Plugins;using MediaBrowser.Controller.Session;using MediaBrowser.Model.Activity;@@ -53,7 +51,6 @@ namespace Emby.Server.Implementations.Activity_installationManager.PackageInstallationFailed += OnPackageInstallationFailed;_sessionManager.SessionStarted += OnSessionStarted;- _sessionManager.AuthenticationSucceeded += OnAuthenticationSucceeded;_sessionManager.SessionEnded += OnSessionEnded;return Task.CompletedTask;@@ -84,25 +81,6 @@ namespace Emby.Server.Implementations.Activity}).ConfigureAwait(false);}- private async void OnAuthenticationSucceeded(object sender, GenericEventArgs<AuthenticationResult> e)- {- var user = e.Argument.User;-- await CreateLogEntry(new ActivityLog(- string.Format(- CultureInfo.InvariantCulture,- _localization.GetLocalizedString("AuthenticationSucceededWithUserName"),- user.Name),- "AuthenticationSucceeded",- user.Id)- {- ShortOverview = string.Format(- CultureInfo.InvariantCulture,- _localization.GetLocalizedString("LabelIpAddressValue"),- e.Argument.SessionInfo.RemoteEndPoint),- }).ConfigureAwait(false);- }-private async void OnSessionStarted(object sender, SessionEventArgs e){var session = e.SessionInfo;@@ -207,7 +185,6 @@ namespace Emby.Server.Implementations.Activity_installationManager.PackageInstallationFailed -= OnPackageInstallationFailed;_sessionManager.SessionStarted -= OnSessionStarted;- _sessionManager.AuthenticationSucceeded -= OnAuthenticationSucceeded;_sessionManager.SessionEnded -= OnSessionEnded;}}diff --git a/Jellyfin.Server.Implementations/Events/Consumers/Security/AuthenticationSucceededLogger.cs b/Jellyfin.Server.Implementations/Events/Consumers/Security/AuthenticationSucceededLogger.csnew file mode 100644index 0000000000..2f9f44ed67--- /dev/null+++ b/Jellyfin.Server.Implementations/Events/Consumers/Security/AuthenticationSucceededLogger.cs@@ -0,0 +1,49 @@+using System.Globalization;+using System.Threading.Tasks;+using Jellyfin.Data.Entities;+using Jellyfin.Data.Events;+using MediaBrowser.Controller.Authentication;+using MediaBrowser.Controller.Events;+using MediaBrowser.Model.Activity;+using MediaBrowser.Model.Globalization;++namespace Jellyfin.Server.Implementations.Events.Consumers.Security+{+ /// <summary>+ /// Creates an entry in the activity log when there is a successful login attempt.+ /// </summary>+ public class AuthenticationSucceededLogger : IEventConsumer<GenericEventArgs<AuthenticationResult>>+ {+ private readonly ILocalizationManager _localizationManager;+ private readonly IActivityManager _activityManager;++ /// <summary>+ /// Initializes a new instance of the <see cref="AuthenticationSucceededLogger"/> class.+ /// </summary>+ /// <param name="localizationManager">The localization manager.</param>+ /// <param name="activityManager">The activity manager.</param>+ public AuthenticationSucceededLogger(ILocalizationManager localizationManager, IActivityManager activityManager)+ {+ _localizationManager = localizationManager;+ _activityManager = activityManager;+ }++ /// <inheritdoc />+ public async Task OnEvent(GenericEventArgs<AuthenticationResult> e)+ {+ await _activityManager.CreateAsync(new ActivityLog(+ string.Format(+ CultureInfo.InvariantCulture,+ _localizationManager.GetLocalizedString("AuthenticationSucceededWithUserName"),+ e.Argument.User.Name),+ "AuthenticationSucceeded",+ e.Argument.User.Id)+ {+ ShortOverview = string.Format(+ CultureInfo.InvariantCulture,+ _localizationManager.GetLocalizedString("LabelIpAddressValue"),+ e.Argument.SessionInfo.RemoteEndPoint),+ }).ConfigureAwait(false);+ }+ }+}