From f69be0ab1b10b1f2070b2f0942e56acc99112e60 Mon Sep 17 00:00:00 2001 From: Alex Cabal Date: Mon, 12 May 2025 09:57:54 -0500 Subject: [PATCH] Update FA login flow to handle new login form --- scripts/ingest-fa-payments | 37 ++++++++++++------- scripts/process-pending-payments | 20 ++++++---- ...d-of-bolshevism-in-an-uncanny-bookshop.php | 1 - 3 files changed, 35 insertions(+), 23 deletions(-) diff --git a/scripts/ingest-fa-payments b/scripts/ingest-fa-payments index 8e92052b..d2b3ffa2 100755 --- a/scripts/ingest-fa-payments +++ b/scripts/ingest-fa-payments @@ -114,33 +114,37 @@ try{ $driver->get('https://fundraising.fracturedatlas.org/admin/general_support/donations?page=' . $page); // Check if we need to log in to FA. - // Wait until the element is visible, then check the current URL. + // Wait until the `` element is visible, then check the current URL. $driver->wait(20, 250)->until(WebDriverExpectedCondition::visibilityOfElementLocated(WebDriverBy::xpath('/html/body'))); - if(stripos($driver->getCurrentURL(), 'auth0.com')){ + if(stripos($driver->getCurrentURL(), 'auth.fracturedatlas.org')){ + // We were redirected to the login page, so try to log in. $log->Write('Logging in to Fractured Atlas ...'); - // We were redirected to the login page, so try to log in. /** @var WebDriverElement $emailField */ - $emailField = $driver->wait(20, 250)->until(WebDriverExpectedCondition::visibilityOfElementLocated(WebDriverBy::xpath('//input[@type="email"]'))); + $emailField = $driver->wait(20, 250)->until(WebDriverExpectedCondition::visibilityOfElementLocated(WebDriverBy::xpath('//input[@inputmode="email"]'))); + $emailField->sendKeys($faUsername); + /** @var WebDriverElement $passwordField */ $passwordField = $driver->wait(20, 250)->until(WebDriverExpectedCondition::visibilityOfElementLocated(WebDriverBy::xpath('//input[@type="password"]'))); - /** @var WebDriverElement $submitButton */ - $submitButton = $driver->wait(20, 250)->until(WebDriverExpectedCondition::visibilityOfElementLocated(WebDriverBy::xpath('//button[@type="submit"]'))); - - // Fill out and submit the form. - $emailField->sendKeys($faUsername); + // FA requires an explicit click on the password field for some reason. + $passwordField->click(); + $passwordField->clear(); $passwordField->sendKeys($faPassword); - $submitButton->click(); + + // Submit the form. + /** @var WebDriverElement $form */ + $form = $driver->wait(20, 250)->until(WebDriverExpectedCondition::visibilityOfElementLocated(WebDriverBy::xpath('//form'))); + $form->submit(); } // Wait until the page finishes loading. // We have to expand the row before we can select its contents, so click the 'expand' button once it's visible. try{ - $toggleButton = $driver->wait(20, 250)->until(WebDriverExpectedCondition::visibilityOfElementLocated(WebDriverBy::xpath('//button[contains(@class, "button-toggle")]'))); + $driver->wait(20, 250)->until(WebDriverExpectedCondition::visibilityOfElementLocated(WebDriverBy::xpath('//button[contains(@class, "button-toggle")]'))); } - catch(Exception){ + catch(Exception $ex){ $log->Write('Error: Couldn\'t load donation list.'); - continue; + throw $ex; } // If the last seen transaction ID is null, get everything from today. @@ -205,7 +209,12 @@ try{ } if($firstTransactionId !== null){ - file_put_contents($transactionFilePath, $firstTransactionId); + try{ + file_put_contents($transactionFilePath, $firstTransactionId); + } + catch(\Exception){ + // Might not have the right permissions, pass. + } } $log->Write('Done.'); diff --git a/scripts/process-pending-payments b/scripts/process-pending-payments index 271e6cdf..34150c8b 100755 --- a/scripts/process-pending-payments +++ b/scripts/process-pending-payments @@ -91,21 +91,25 @@ try{ // Check if we need to log in to FA. // Wait until the `` element is visible, then check the current URL. $driver->wait(20, 250)->until(WebDriverExpectedCondition::visibilityOfElementLocated(WebDriverBy::xpath('/html/body'))); - if(stripos($driver->getCurrentURL(), 'auth0.com')){ + if(stripos($driver->getCurrentURL(), 'auth.fracturedatlas.org')){ $log->Write('Logging in to Fractured Atlas ...'); // We were redirected to the login page, so try to log in. /** @var WebDriverElement $emailField */ - $emailField = $driver->wait(20, 250)->until(WebDriverExpectedCondition::visibilityOfElementLocated(WebDriverBy::xpath('//input[@type="email"]'))); + $emailField = $driver->wait(20, 250)->until(WebDriverExpectedCondition::visibilityOfElementLocated(WebDriverBy::xpath('//input[@inputmode="email"]'))); + $emailField->sendKeys($faUsername); + /** @var WebDriverElement $passwordField */ $passwordField = $driver->wait(20, 250)->until(WebDriverExpectedCondition::visibilityOfElementLocated(WebDriverBy::xpath('//input[@type="password"]'))); - /** @var WebDriverElement $submitButton */ - $submitButton = $driver->wait(20, 250)->until(WebDriverExpectedCondition::visibilityOfElementLocated(WebDriverBy::xpath('//button[@type="submit"]'))); - - // Fill out and submit the form. - $emailField->sendKeys($faUsername); + // FA requires an explicit click on the password field for some reason. + $passwordField->click(); + $passwordField->clear(); $passwordField->sendKeys($faPassword); - $submitButton->click(); + + // Submit the form. + /** @var WebDriverElement $form */ + $form = $driver->wait(20, 250)->until(WebDriverExpectedCondition::visibilityOfElementLocated(WebDriverBy::xpath('//form'))); + $form->submit(); } // Wait until the page finishes loading. diff --git a/www/blog/a-kind-of-bolshevism-in-an-uncanny-bookshop.php b/www/blog/a-kind-of-bolshevism-in-an-uncanny-bookshop.php index 20444c59..c93d9190 100644 --- a/www/blog/a-kind-of-bolshevism-in-an-uncanny-bookshop.php +++ b/www/blog/a-kind-of-bolshevism-in-an-uncanny-bookshop.php @@ -33,4 +33,3 @@ $carousel = Db::Query('SELECT * from Ebooks where EbookId in ' . Db::CreateSetSq -