Commit 30bf4fee authored by Maxime Gasselin's avatar Maxime Gasselin Committed by Vincent A

[lcl] Handle login redirection without 2fa

If no 2fa we get a redirection to contract page (before we got a 200).

Closes: 61970@sibi
parent c0922ad8
......@@ -25,7 +25,10 @@ import time
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):
contracts_choice = URL(r'.*outil/UAUT/Contract/routing', ContractsChoicePage)
home = URL(r'/outil/UWHO/Accueil/', HomePage)
......@@ -196,8 +200,22 @@ class LCLBrowser(LoginBrowser, StatesMixin):
# if the session expire
# Must set the referer to avoid redirection to the home page
self.login.go(headers={"Referer": ""})
try:, self.password)
except BrowserUnavailable:
if not, 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')
# If we're not redirected to 2fa page, it's likely to be the home page and we're logged in
if self.login.is_here():
if not self.contracts and not self.parsed_contracts:
......@@ -176,17 +176,7 @@ class LoginPage(HTMLPage):
except AttributeError:
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
def check_error(self):
errors = self.doc.xpath(u'//*[@class="erreur" or @class="messError"]')
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment