[weboob] [PATCH 1/4] [ameli] handle authentication errors

Pierre-Louis Bonicoli pierre-louis.bonicoli at gmx.fr
Sun Jul 26 02:07:08 CEST 2015


Signed-off-by: Pierre-Louis Bonicoli <pierre-louis.bonicoli at gmx.fr>
---
 modules/ameli/browser.py | 9 +++++++--
 modules/ameli/pages.py   | 9 +++++++++
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/modules/ameli/browser.py b/modules/ameli/browser.py
index 6af5345..b8002b9 100644
--- a/modules/ameli/browser.py
+++ b/modules/ameli/browser.py
@@ -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()
diff --git a/modules/ameli/pages.py b/modules/ameli/pages.py
index 14c1404..21be3f3 100644
--- a/modules/ameli/pages.py
+++ b/modules/ameli/pages.py
@@ -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
 
-- 
2.1.4




More information about the weboob mailing list