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;
using MediaBrowser.Model.Notifications;
using Microsoft.Extensions.Logging;
namespace Jellyfin.Server.Implementations.Events.Consumers.Users
{
///
/// Creates an entry in the activity log when a user is locked out.
///
public class UserLockedOutLogger : IEventConsumer
{
private readonly ILocalizationManager _localizationManager;
private readonly IActivityManager _activityManager;
///
/// Initializes a new instance of the class.
///
/// The localization manager.
/// The activity manager.
public UserLockedOutLogger(ILocalizationManager localizationManager, IActivityManager activityManager)
{
_localizationManager = localizationManager;
_activityManager = activityManager;
}
///
public async Task OnEvent(UserLockedOutEventArgs eventArgs)
{
await _activityManager.CreateAsync(new ActivityLog(
string.Format(
CultureInfo.InvariantCulture,
_localizationManager.GetLocalizedString("UserLockedOutWithName"),
eventArgs.Argument.Username),
NotificationType.UserLockedOut.ToString(),
eventArgs.Argument.Id)
{
LogSeverity = LogLevel.Error
}).ConfigureAwait(false);
}
}
}