[weboob] [PATCH 1/1] LCL: deal with wrong passwords

Pierre Mazière pierre.maziere at gmail.com
Wed Mar 9 01:41:52 CET 2011


Signed-off-by: Pierre Mazière <pierre.maziere at gmail.com>
---
 weboob/backends/lcl/browser.py |   16 +++++++++++-----
 weboob/backends/lcl/pages.py   |   12 ++++++++++--
 2 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/weboob/backends/lcl/browser.py b/weboob/backends/lcl/browser.py
index 5932f10..0b64ba2 100644
--- a/weboob/backends/lcl/browser.py
+++ b/weboob/backends/lcl/browser.py
@@ -18,7 +18,7 @@
 
 from weboob.tools.browser import BaseBrowser, BrowserIncorrectPassword
 
-from .pages import LoginPage, LoginErrorPage, FramePage, AccountsPage, AccountHistoryPage
+from .pages import LoginPage, LoginResultPage, FramePage, AccountsPage, AccountHistoryPage
 
 
 __all__ = ['LCLBrowser']
@@ -32,7 +32,7 @@ class LCLBrowser(BaseBrowser):
     USER_AGENT = BaseBrowser.USER_AGENTS['wget']
     PAGES = {
         'https://particuliers.secure.lcl.fr/index.html':   LoginPage,
-        'https://particuliers.secure.lcl.fr/everest/UWBI/UWBIAccueil\?DEST=IDENTIFICATION': LoginErrorPage,
+        'https://particuliers.secure.lcl.fr/everest/UWBI/UWBIAccueil\?DEST=IDENTIFICATION': LoginResultPage,
         'https://particuliers.secure.lcl.fr/outil/UWSP/Synthese/accesSynthese': AccountsPage,
         'https://particuliers.secure.lcl.fr/outil/UWB2/Accueil\?DEST=INIT': FramePage,
         'https://particuliers.secure.lcl.fr/outil/UWLM/ListeMouvementsPro/accesListeMouvementsPro.*':  AccountHistoryPage,
@@ -48,16 +48,22 @@ class LCLBrowser(BaseBrowser):
     def login(self):
         assert isinstance(self.username, basestring)
         assert isinstance(self.password, basestring)
+        assert self.password.isdigit()
+        assert isinstance(self.agency, basestring)
+        assert self.agency.isdigit()
 
         if not self.is_on_page(LoginPage):
-            self.location('https://particuliers.secure.lcl.fr/', no_login=True)
+            self.location('%s://%s/index.html' % (self.PROTOCOL, self.DOMAIN),\
+                          no_login=True)
 
         self.page.login(self.agency, self.username, self.password)
 
-        if not self.is_logged():
+        if not self.is_logged() or \
+           (self.is_on_page(LoginResultPage) and self.page.is_error()) :
             raise BrowserIncorrectPassword()
 
-        self.location('%s://%s/outil/UWSP/Synthese/accesSynthese' % (self.PROTOCOL, self.DOMAIN))
+        self.location('%s://%s/outil/UWSP/Synthese/accesSynthese' \
+                      % (self.PROTOCOL, self.DOMAIN))
 
     def get_accounts_list(self):
         if not self.is_on_page(AccountsPage):
diff --git a/weboob/backends/lcl/pages.py b/weboob/backends/lcl/pages.py
index 830c243..a8e4dba 100644
--- a/weboob/backends/lcl/pages.py
+++ b/weboob/backends/lcl/pages.py
@@ -29,8 +29,16 @@ class LoginPage(BasePage):
         self.browser['CodeId'] = passwd
         self.browser.submit()
 
-class LoginErrorPage(BasePage):
-    pass
+class LoginResultPage(BasePage):
+    def is_error(self):
+        for text in self.document.find('body').itertext():
+            text=text.strip()
+            # Login seems valid, but password does not
+            needle='Les données saisies sont incorrectes'
+            if text.startswith(needle.decode('utf-8')):
+                return True
+
+        return False
 
 class FramePage(BasePage):
     pass
-- 
1.7.2.3




More information about the weboob mailing list