Browse Source

(Hopefully) less buggy 2FA

pull/31/head
Wesley Kerfoot 6 years ago
parent
commit
d0be69bbbb
  1. 48
      deletefb/tools/login.py

48
deletefb/tools/login.py

@ -2,6 +2,7 @@ import time
from selenium.webdriver.chrome.options import Options from selenium.webdriver.chrome.options import Options
from seleniumrequests import Chrome from seleniumrequests import Chrome
from selenium.common.exceptions import NoSuchElementException
def login(user_email_address, def login(user_email_address,
user_password, user_password,
@ -46,23 +47,34 @@ def login(user_email_address,
loginelement = driver.find_element_by_id(login) loginelement = driver.find_element_by_id(login)
loginelement.click() loginelement.click()
if "two-factor authentication" in driver.page_source.lower(): # Defaults to no 2fa
if two_factor_token: has_2fa = False
twofactorelement = driver.find_element_by_name(approvals_code) try:
twofactorelement.send_keys(two_factor_token) # If this element exists, we've reached a 2FA page
driver.find_element_by_xpath("//form[@class=\"checkpoint\"]")
# Submits after the code is passed into the form, does not validate 2FA code. driver.find_element_by_xpath("//input[@name=\"approvals_code\"]")
contelement = driver.find_element_by_id("checkpointSubmitButton") has_2fa = True
contelement.click() except NoSuchElementException:
has_2fa = "two-factor authentication" in driver.page_source.lower() or has_2fa
# Defaults to saving this new browser, this occurs on each new automated login.
save_browser = driver.find_element_by_id("checkpointSubmitButton") if two_factor_token and has_2fa:
save_browser.click() twofactorelement = driver.find_element_by_name(approvals_code)
else: twofactorelement.send_keys(two_factor_token)
# Allow time to enter 2FA code
print("Pausing to enter 2FA code") # Submits after the code is passed into the form, does not validate 2FA code.
time.sleep(20) contelement = driver.find_element_by_id("checkpointSubmitButton")
print("Continuing execution") contelement.click()
# Defaults to saving this new browser, this occurs on each new automated login.
save_browser = driver.find_element_by_id("checkpointSubmitButton")
save_browser.click()
elif has_2fa:
# Allow time to enter 2FA code
print("Pausing to enter 2FA code")
time.sleep(35)
print("Continuing execution")
else:
pass
return driver return driver

Loading…
Cancel
Save