handle authentication errors

Signed-off-by: Pierre-Louis Bonicoli <pierre-louis.bonicoli@gmx.fr>
This commit is contained in:
Pierre-Louis Bonicoli 2015-07-26 02:07:08 +02:00 committed by Florent
commit a40abf539f
2 changed files with 16 additions and 2 deletions

View file

@ -21,7 +21,7 @@ from weboob.browser import LoginBrowser, URL, need_login
from weboob.exceptions import BrowserIncorrectPassword
from weboob.capabilities.bill import Detail
from decimal import Decimal
from .pages import LoginPage, HomePage, AccountPage, LastPaymentsPage, PaymentDetailsPage, BillsPage
from .pages import LoginPage, LoginValidationPage, HomePage, AccountPage, LastPaymentsPage, PaymentDetailsPage, BillsPage
__all__ = ['AmeliBrowser']
@ -30,6 +30,7 @@ class AmeliBrowser(LoginBrowser):
BASEURL = 'https://assure.ameli.fr'
loginp = URL('/PortailAS/appmanager/PortailAS/assure\?.*_pageLabel=as_login_page', LoginPage)
login_validationp = URL('https://assure.ameli.fr:443/PortailAS/appmanager/PortailAS/assure;jsessionid=[a-zA-Z0-9!;-]+\?_nfpb=true&_windowLabel=connexioncompte_2&connexioncompte_2_actionOverride=%2Fportlets%2Fconnexioncompte%2Fvalidationconnexioncompte&_pageLabel=as_login_page$', LoginValidationPage)
homep = URL('/PortailAS/appmanager/PortailAS/assure\?_nfpb=true&_pageLabel=as_accueil_page', HomePage)
accountp = URL('/PortailAS/appmanager/PortailAS/assure\?_nfpb=true&_pageLabel=as_info_perso_page', AccountPage)
billsp = URL('/PortailAS/appmanager/PortailAS/assure\?_nfpb=true&_pageLabel=as_revele_mensuel_presta_page', BillsPage)
@ -50,7 +51,11 @@ class AmeliBrowser(LoginBrowser):
self.page.login(self.username, self.password)
self.homep.stay_or_go() # Redirection not interpreted by browser. Mannually redirect on homep
error = self.page.is_error()
if error:
raise BrowserIncorrectPassword(error)
self.homep.stay_or_go() # Redirection not interpreted by browser. Mannually redirect on homep
if not self.homep.is_here():
raise BrowserIncorrectPassword()

View file

@ -38,6 +38,12 @@ class AmeliBasePage(HTMLPage):
self.logger.debug('logged: %s' % (logged))
return logged
def is_error(self):
errors = self.doc.xpath(u'//*[@id="r_errors"]')
if errors:
return errors[0].text_content()
return False
class LoginPage(AmeliBasePage):
def login(self, login, password):
form = self.get_form('//form[@name="connexionCompteForm"]')
@ -45,6 +51,9 @@ class LoginPage(AmeliBasePage):
form['connexioncompte_2codeConfidentiel'] = password.encode('utf8')
form.submit()
class LoginValidationPage(AmeliBasePage):
pass
class HomePage(AmeliBasePage):
pass