Fixed: (GreatPosterWall) Use cookies for 2FA

Co-authored-by: ilike2burnthing <59480337+ilike2burnthing@users.noreply.github.com>
This commit is contained in:
Bogdan
2023-02-23 07:01:36 +02:00
committed by GitHub
parent 5f26287234
commit 26bea14137
7 changed files with 72 additions and 37 deletions
@@ -0,0 +1,31 @@
using FluentValidation;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.Annotations;
using NzbDrone.Core.Indexers.Settings;
using NzbDrone.Core.Validation;
namespace NzbDrone.Core.Indexers.Definitions.Gazelle;
public class GazelleUserPassOrCookieValidator<T> : NoAuthSettingsValidator<T>
where T : GazelleUserPassOrCookieSettings
{
public GazelleUserPassOrCookieValidator()
{
RuleFor(c => c.Username).NotEmpty().When(c => c.Cookie.IsNullOrWhiteSpace());
RuleFor(c => c.Password).NotEmpty().When(c => c.Cookie.IsNullOrWhiteSpace());
RuleFor(c => c.Cookie).NotEmpty().When(c => c.Username.IsNullOrWhiteSpace() && c.Password.IsNullOrWhiteSpace());
}
}
public class GazelleUserPassOrCookieSettings : GazelleSettings
{
private static readonly GazelleUserPassOrCookieValidator<GazelleUserPassOrCookieSettings> Validator = new ();
[FieldDefinition(4, Label = "Cookie", HelpText = "Use the Cookie field only if 2FA is enabled for your account, leave it empty otherwise.", Privacy = PrivacyLevel.Password)]
public string Cookie { get; set; }
public override NzbDroneValidationResult Validate()
{
return new NzbDroneValidationResult(Validator.Validate(this));
}
}