From 30bf4fee5a83555dffad1d9437c4505cb182ae3a Mon Sep 17 00:00:00 2001 From: Maxime Gasselin Date: Tue, 17 Mar 2020 17:14:30 +0100 Subject: [PATCH] [lcl] Handle login redirection without 2fa If no 2fa we get a redirection to contract page (before we got a 200). Closes: 61970@sibi --- modules/lcl/browser.py | 22 ++++++++++++++++++++-- modules/lcl/pages.py | 12 +----------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/modules/lcl/browser.py b/modules/lcl/browser.py index b613476a80..b463dbe2d4 100644 --- a/modules/lcl/browser.py +++ b/modules/lcl/browser.py @@ -25,7 +25,10 @@ from datetime import datetime, timedelta, date from functools import wraps -from weboob.exceptions import BrowserIncorrectPassword, BrowserUnavailable, AuthMethodNotImplemented +from weboob.exceptions import ( + BrowserIncorrectPassword, BrowserUnavailable, + AuthMethodNotImplemented, ActionNeeded, +) from weboob.browser import LoginBrowser, URL, need_login, StatesMixin from weboob.browser.exceptions import ServerError from weboob.capabilities.base import NotAvailable @@ -67,6 +70,7 @@ class LCLBrowser(LoginBrowser, StatesMixin): r'/outil/UAUT/Contract/getContract.*', r'/outil/UAUT/Contract/selectContracts.*', r'/outil/UAUT/Accueil/preRoutageLogin', + r'/outil/UAUT/Contract/redirection', ContractsPage) contracts_choice = URL(r'.*outil/UAUT/Contract/routing', ContractsChoicePage) home = URL(r'/outil/UWHO/Accueil/', HomePage) @@ -196,8 +200,22 @@ def do_login(self): # if the session expire # Must set the referer to avoid redirection to the home page self.login.go(headers={"Referer": "https://www.lcl.fr/"}) + try: + self.page.login(self.username, self.password) + except BrowserUnavailable: + self.page.check_error() - if not self.page.login(self.username, self.password) or self.login.is_here(): + if self.response.status_code == 302: + if 'AuthentForteDesktop' in self.response.headers['location']: + # If we follow the redirection we will get a 2fa + # The 2fa validation is crossbrowser, for now we raise an ActionNeeded + # TODO Handle SMS and appvalidation + raise ActionNeeded('Vous devez réaliser la double authentification sur le portail internet') + else: + # If we're not redirected to 2fa page, it's likely to be the home page and we're logged in + self.location(self.response.headers['location']) + + if self.login.is_here(): self.page.check_error() if not self.contracts and not self.parsed_contracts: diff --git a/modules/lcl/pages.py b/modules/lcl/pages.py index d35c3abe3f..9e94b9caac 100644 --- a/modules/lcl/pages.py +++ b/modules/lcl/pages.py @@ -176,17 +176,7 @@ def login(self, login, passwd): except AttributeError: pass - try: - form_page = form.submit(allow_redirects=False) - if form_page.status_code == 302 and 'AuthentForteDesktop' in form_page.headers['location']: - # 2fa if we follow the redirection - # SMS and appvalidation exist - raise ActionNeeded('Vous devez réaliser la double authentification sur le portail internet') - # If no 2FA the submit gives a 200 - except BrowserUnavailable: - # Login is not valid - return False - return True + form.submit(allow_redirects=False) def check_error(self): errors = self.doc.xpath(u'//*[@class="erreur" or @class="messError"]') -- GitLab