From b70f38b8ff487b6aafe65c0b8475f3e6d5637114 Mon Sep 17 00:00:00 2001
From: takosine <59401293+takosine@users.noreply.github.com>
Date: Sun, 5 Jan 2020 12:43:54 -0800
Subject: [PATCH] PassThePopcorn: change login to support 2fa (#6823) resolves
#6649
---
src/Jackett.Common/Indexers/PassThePopcorn.cs | 54 +++++++++----------
...DataAPILoginWithUserAndPasskeyAndFilter.cs | 30 +++++++++++
2 files changed, 55 insertions(+), 29 deletions(-)
create mode 100644 src/Jackett.Common/Models/IndexerConfig/ConfigurationDataAPILoginWithUserAndPasskeyAndFilter.cs
diff --git a/src/Jackett.Common/Indexers/PassThePopcorn.cs b/src/Jackett.Common/Indexers/PassThePopcorn.cs
index 8abc7772e..2d3af86a5 100644
--- a/src/Jackett.Common/Indexers/PassThePopcorn.cs
+++ b/src/Jackett.Common/Indexers/PassThePopcorn.cs
@@ -23,9 +23,9 @@ namespace Jackett.Common.Indexers
private string DetailURL { get { return "https://passthepopcorn.me/torrents.php?torrentid="; } }
private string AuthKey { get; set; }
- private new ConfigurationDataBasicLoginWithFilterAndPasskey configData
+ private new ConfigurationDataAPILoginWithUserAndPasskeyAndFilter configData
{
- get { return (ConfigurationDataBasicLoginWithFilterAndPasskey)base.configData; }
+ get { return (ConfigurationDataAPILoginWithUserAndPasskeyAndFilter)base.configData; }
set { base.configData = value; }
}
@@ -38,7 +38,7 @@ namespace Jackett.Common.Indexers
client: c,
logger: l,
p: ps,
- configData: new ConfigurationDataBasicLoginWithFilterAndPasskey(@"Enter filter options below to restrict search results.
+ configData: new ConfigurationDataAPILoginWithUserAndPasskeyAndFilter(@"Enter filter options below to restrict search results.
Separate options with a space if using more than one option.
Filter options available:
GoldenPopcorn
Scene
Checked
Free
"))
{
@@ -69,29 +69,21 @@ namespace Jackett.Common.Indexers
{
LoadValuesFromJson(configJson);
- await DoLogin();
-
- return IndexerConfigurationStatus.RequiresTesting;
- }
-
- private async Task DoLogin()
- {
- var pairs = new Dictionary {
- { "username", configData.Username.Value },
- { "password", configData.Password.Value },
- { "passkey", configData.Passkey.Value },
- { "keeplogged", "1" },
- { "login", "Log In!" }
- };
-
- var response = await RequestLoginAndFollowRedirect(LoginUrl, pairs, null, true, indexUrl, SiteLink);
- JObject js_response = JObject.Parse(response.Content);
- await ConfigureIfOK(response.Cookies, response.Content != null && (string)js_response["Result"] != "Error", () =>
+ IsConfigured = false;
+ try
{
- // Landing page wil have "Result":"Error" if log in fails
- string errorMessage = (string)js_response["Message"];
- throw new ExceptionWithConfigData(errorMessage, configData);
- });
+ var results = await PerformQuery(new TorznabQuery());
+ if (results.Count() == 0)
+ throw new Exception("Testing returned no results!");
+ IsConfigured = true;
+ SaveConfig();
+ }
+ catch (Exception e)
+ {
+ throw new ExceptionWithConfigData(e.Message, configData);
+ }
+
+ return IndexerConfigurationStatus.Completed;
}
protected override async Task> PerformQuery(TorznabQuery query)
@@ -124,12 +116,16 @@ namespace Jackett.Common.Indexers
movieListSearchUrl += "?" + queryCollection.GetQueryString();
}
- var results = await RequestStringWithCookiesAndRetry(movieListSearchUrl);
+ var authHeaders = new Dictionary()
+ {
+ { "ApiUser", configData.User.Value },
+ { "ApiKey", configData.Key.Value }
+ };
+
+ var results = await RequestStringWithCookiesAndRetry(movieListSearchUrl, null, null, authHeaders);
if (results.IsRedirect) // untested
{
- // re-login
- await DoLogin();
- results = await RequestStringWithCookiesAndRetry(movieListSearchUrl);
+ results = await RequestStringWithCookiesAndRetry(movieListSearchUrl, null, null, authHeaders);
}
try
{
diff --git a/src/Jackett.Common/Models/IndexerConfig/ConfigurationDataAPILoginWithUserAndPasskeyAndFilter.cs b/src/Jackett.Common/Models/IndexerConfig/ConfigurationDataAPILoginWithUserAndPasskeyAndFilter.cs
new file mode 100644
index 000000000..7d4292f51
--- /dev/null
+++ b/src/Jackett.Common/Models/IndexerConfig/ConfigurationDataAPILoginWithUserAndPasskeyAndFilter.cs
@@ -0,0 +1,30 @@
+namespace Jackett.Common.Models.IndexerConfig
+{
+ public class ConfigurationDataAPILoginWithUserAndPasskeyAndFilter : ConfigurationData
+ {
+ public StringItem Passkey { get; private set; }
+ public DisplayItem KeyHint { get; private set; }
+ public StringItem User { get; private set; }
+ public StringItem Key { get; private set; }
+ public DisplayItem FilterExample { get; private set; }
+ public StringItem FilterString { get; private set; }
+
+ public ConfigurationDataAPILoginWithUserAndPasskeyAndFilter(string FilterInstructions)
+ {
+ Passkey = new StringItem { Name = "Passkey", Value = string.Empty };
+
+ KeyHint = new DisplayItem("- Visit the security tab on your user settings page to access your ApiUser and ApiKey
- If you haven't yet generated a key, you may have to first generate one using the checkbox below your keys
")
+ {
+ Name = "API Authentication"
+ };
+ User = new StringItem { Name = "ApiUser", Value = string.Empty };
+ Key = new StringItem { Name = "ApiKey", Value = string.Empty };
+
+ FilterExample = new DisplayItem(FilterInstructions)
+ {
+ Name = ""
+ };
+ FilterString = new StringItem { Name = "Filters (optional)" };
+ }
+ }
+}
\ No newline at end of file