Commit 37fd1da8 authored by Ilyas Semmaoui's avatar Ilyas Semmaoui Committed by Vincent A

[amazon] handle account switcher

Sometimes we can face a page asking if we want to use another account or the
account currently used
parent b99e3142
......@@ -33,7 +33,7 @@
from .pages import (
LoginPage, SubscriptionsPage, DocumentsPage, DownloadDocumentPage, HomePage,
SecurityPage, LanguagePage, HistoryPage, PasswordExpired, ApprovalPage, PollingPage,
ResetPasswordPage,
ResetPasswordPage, AccountSwitcherLoadingPage, AccountSwitcherPage, SwitchedAccountPage,
)
......@@ -63,10 +63,15 @@ class AmazonBrowser(LoginBrowser, StatesMixin):
"Impossible de trouver un compte correspondant à cette adresse e-mail",
"L'adresse e-mail est déjà utilisée",
"Numéro de téléphone incorrect",
"Votre adresse e-mail ou mot de passe étaient incorrects",
]
WRONG_CAPTCHA_RESPONSE = "Saisissez les caractères tels qu'ils apparaissent sur l'image."
login = URL(r'/ap/signin(.*)', LoginPage)
account_switcher_loading = URL(r'/ap/signin(.*)', AccountSwitcherLoadingPage)
account_switcher = URL(r'/ap/cvf/request.embed\?arb=(?P<token>.*)', AccountSwitcherPage)
switched_account = URL(r'/ap/switchaccount', SwitchedAccountPage)
home = URL(r'/$', r'/\?language=.+$', HomePage)
subscriptions = URL(r'/gp/profile', SubscriptionsPage)
history = URL(
......@@ -281,6 +286,11 @@ def do_login(self):
else:
self.history.go()
if self.account_switcher_loading.is_here():
self.account_switcher.go(token=self.page.get_arb_token())
self.page.validate_account()
self.location(self.page.get_redirect_url())
if not self.login.is_here():
return
......
......@@ -20,9 +20,10 @@
from __future__ import unicode_literals
from woob.browser.exceptions import ServerError
from woob.browser.pages import HTMLPage, LoggedPage, FormNotFound, PartialHTMLPage, pagination
from woob.browser.pages import HTMLPage, LoggedPage, FormNotFound, PartialHTMLPage, pagination, JsonPage
from woob.browser.elements import ItemElement, ListElement, method
from woob.browser.filters.html import Link, Attr
from woob.browser.filters.json import Dict
from woob.browser.filters.standard import (
CleanText, CleanDecimal, Env, Regexp, Format, RawText,
Field, Currency, Date, Async, AsyncLoad,
......@@ -135,7 +136,31 @@ class LanguagePage(HTMLPage):
pass
class AccountSwitcherLoadingPage(HTMLPage):
def is_here(self):
return bool(self.doc.xpath('//div[@id="ap-account-switcher-container"]'))
def get_arb_token(self):
# Get the token from attribute data-arbToken (data-arbtoken using the Attr filter)
return Attr('//div[@id="ap-account-switcher-container"]', 'data-arbtoken')(self.doc)
class AccountSwitcherPage(PartialHTMLPage):
def validate_account(self):
form = self.get_form(xpath='//form[@action="/ap/switchaccount"]')
form['switch_account_request'] = Attr('//a[@data-name="switch_account_request"]', 'data-value')(self.doc)
form.submit()
class SwitchedAccountPage(JsonPage):
def get_redirect_url(self):
return Dict('redirectUrl')(self.doc)
class LoginPage(PartialHTMLPage):
def is_here(self):
return not bool(self.doc.xpath('//div[@id="ap-account-switcher-container"]'))
ENCODING = 'utf-8'
def login(self, login, password, captcha=None):
......
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