diff --git a/modules/creditdunord/browser.py b/modules/creditdunord/browser.py index da20f469c4c2af3c9325dce890c1edb8fc75880c..21f676498693d69eee372927d5056aa0ffb219a2 100644 --- a/modules/creditdunord/browser.py +++ b/modules/creditdunord/browser.py @@ -36,6 +36,7 @@ class CreditDuNordBrowser(LoginBrowser): login = URL('$', '/.*\?.*_pageLabel=page_erreur_connexion', + '/.*\?.*_pageLabel=reinitialisation_mot_de_passe', LoginPage) redirect = URL('/swm/redirectCDN.html', RedirectPage) entrypage = URL('/icd/zco/#zco', EntryPage) @@ -64,37 +65,25 @@ def logged(self): def do_login(self): self.login.go().login(self.username, self.password) - if self.redirect.is_here(): - self.page.check_error() if self.accounts.is_here(): expired_error = self.page.get_password_expired() if expired_error: raise BrowserPasswordExpired(expired_error) - if self.login.is_here(): + # Force redirection to entry page if the redirect page does not contain an url + if self.redirect.is_here(): + self.entrypage.go() + + if self.entrypage.is_here() or self.login.is_here(): error = self.page.get_error() if error: + if 'code confidentiel à la première connexion' in error: + raise BrowserPasswordExpired(error) raise BrowserIncorrectPassword(error) - else: - # in case we are still on login without error message - # we'll check what's happening. - assert False, "Still on login page." if not self.logged: raise BrowserIncorrectPassword() - # The redirection page may contain a message - if self.page.doc.xpath('//head[title="Authentification"]/script[contains(text(), "_pageLabel=reinitialisation_mot_de_passe")]'): - raise BrowserPasswordExpired() - - if not self.entrypage.is_here(): - self.entrypage.go() - - # The main page may contain a message as well - msg = 'vous devez modifier votre code confidentiel à la première connexion puis tous les 12 mois' - if self.page.doc.xpath('//b[contains(text(), "%s")]' % msg): - raise BrowserPasswordExpired(msg.capitalize()) - def _iter_accounts(self): self.loans.go(account_type=self.account_type, loans_page_label=self.loans_page_label) for a in self.page.get_list(): diff --git a/modules/creditdunord/pages.py b/modules/creditdunord/pages.py index 549d153bed4a9ab7310b85815febbd03193c87b8..dfdf1e332d9876d01c68ba4fa62de9b96bdff151 100755 --- a/modules/creditdunord/pages.py +++ b/modules/creditdunord/pages.py @@ -97,23 +97,26 @@ def get_string_code(self, string): return ','.join(res) +class HTMLErrorPage(HTMLPage): + def get_error(self): + # No Coalesce here as both can be empty + return CleanText('//b[has-class("x-attentionErreurLigneHaut")]')(self.doc) or \ + CleanText('//div[has-class("x-attentionErreur")]/b')(self.doc) + + + class RedirectPage(HTMLPage): - def check_error(self): - error = CleanText(self.doc.xpath('//script[contains(text(), "erreur")]'))(self) - if error: - error_link = re.search(r'href="(.*)"', error).group(1) - error_page = self.browser.location(error_link) - err_message = CleanText(error_page.page.doc.xpath('//div/b[contains(@class, "attentionErreur")]'))(self) - if err_message == "Nous n'avons pas pu vous authentifier.": - raise BrowserIncorrectPassword("Nous n'avons pas pu vous authentifier.") - assert False, 'Never seen this error message before: %s' % err_message - - -class EntryPage(LoggedPage, HTMLPage): + def on_load(self): + link = Regexp(CleanText('//script'), 'href="(.*)"', default='')(self.doc) + if link: + self.browser.location(link) + + +class EntryPage(LoggedPage, HTMLErrorPage): pass -class LoginPage(HTMLPage): +class LoginPage(HTMLErrorPage): VIRTUALKEYBOARD = CDNVirtKeyboard def login(self, username, password): @@ -155,9 +158,6 @@ def classic_login(self, username, password): } self.browser.location('/saga/authentification', data=data) - def get_error(self): - return CleanText('//b[has-class("x-attentionErreurLigneHaut")]', default="")(self.doc) - class AccountTypePage(LoggedPage, JsonPage): def get_account_type(self):