jellyfin/Jellyfin.Api/Auth/FirstTimeOrIgnoreParentalControlSetupPolicy/FirstTimeOrIgnoreParentalControlSetupHandler.cs

57 lines
2.3 KiB
C#
Raw Normal View History

using System.Threading.Tasks;
2020-08-06 07:17:45 -07:00
using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Library;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
2020-08-06 16:59:48 -07:00
namespace Jellyfin.Api.Auth.FirstTimeOrIgnoreParentalControlSetupPolicy
{
/// <summary>
2020-08-06 16:59:48 -07:00
/// Ignore parental control schedule and allow before startup wizard has been completed.
/// </summary>
2020-08-09 12:51:25 -07:00
public class FirstTimeOrIgnoreParentalControlSetupHandler : BaseAuthorizationHandler<FirstTimeOrIgnoreParentalControlSetupRequirement>
{
2020-08-06 07:17:45 -07:00
private readonly IConfigurationManager _configurationManager;
/// <summary>
2020-08-06 16:59:48 -07:00
/// Initializes a new instance of the <see cref="FirstTimeOrIgnoreParentalControlSetupHandler"/> class.
/// </summary>
/// <param name="userManager">Instance of the <see cref="IUserManager"/> interface.</param>
/// <param name="networkManager">Instance of the <see cref="INetworkManager"/> interface.</param>
/// <param name="httpContextAccessor">Instance of the <see cref="IHttpContextAccessor"/> interface.</param>
2020-08-06 07:17:45 -07:00
/// <param name="configurationManager">Instance of the <see cref="IConfigurationManager"/> interface.</param>
2020-08-06 16:59:48 -07:00
public FirstTimeOrIgnoreParentalControlSetupHandler(
IUserManager userManager,
INetworkManager networkManager,
2020-08-06 07:17:45 -07:00
IHttpContextAccessor httpContextAccessor,
IConfigurationManager configurationManager)
: base(userManager, networkManager, httpContextAccessor)
{
2020-08-06 07:17:45 -07:00
_configurationManager = configurationManager;
}
/// <inheritdoc />
2020-08-09 12:51:25 -07:00
protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, FirstTimeOrIgnoreParentalControlSetupRequirement requirement)
{
2020-08-06 16:59:48 -07:00
if (!_configurationManager.CommonConfiguration.IsStartupWizardCompleted)
{
context.Succeed(requirement);
return Task.CompletedTask;
}
var validated = ValidateClaims(context.User, ignoreSchedule: true);
2020-08-06 16:59:48 -07:00
if (validated)
2020-08-06 07:17:45 -07:00
{
context.Succeed(requirement);
}
else
{
context.Fail();
}
return Task.CompletedTask;
}
}
}