Пример #1
0
 def login_auth_data(self, data=None, password=None):
     """Perform account login with authentication data"""
     from requests import exceptions
     LOG.debug('Logging in with authentication data')
     # Add the cookies to the session
     self.session.cookies.clear()
     for cookie in data['cookies']:
         self.session.cookies.set(cookie[0], cookie[1], **cookie[2])
     cookies.log_cookie(self.session.cookies)
     # Try access to website
     try:
         website.extract_session_data(self.get('browse'),
                                      validate=True,
                                      update_profiles=True)
     except MbrStatusAnonymousError:
         # Access not valid
         return False
     # Get the account e-mail
     page_response = self.get('your_account').decode('utf-8')
     email_match = re.search(r'account-email[^<]+>([^<]+@[^</]+)</',
                             page_response)
     email = email_match.group(1).strip() if email_match else None
     if not email:
         raise WebsiteParsingError('E-mail field not found')
     # Verify the password (with parental control api)
     try:
         response = self.post_safe('profile_hub',
                                   data={
                                       'destination':
                                       'contentRestrictions',
                                       'guid':
                                       G.LOCAL_DB.get_active_profile_guid(),
                                       'password':
                                       password,
                                       'task':
                                       'auth'
                                   })
         if response.get('status') != 'ok':
             raise LoginError(common.get_local_string(
                 12344))  # 12344=Passwords entered did not match.
     except exceptions.HTTPError as exc:
         if exc.response.status_code == 500:
             # This endpoint raise HTTP error 500 when the password is wrong
             raise LoginError(common.get_local_string(12344)) from exc
         raise
     common.set_credentials({'email': email, 'password': password})
     LOG.info('Login successful')
     ui.show_notification(common.get_local_string(30109))
     cookies.save(self.session.cookies)
     return True
Пример #2
0
 def login_auth_data(self, data=None, password=None):
     """Perform account login with authentication data"""
     LOG.debug('Logging in with authentication data')
     # Add the cookies to the session
     self.session.cookies.clear()
     for cookie in data['cookies']:
         # The code below has been adapted from httpx.Cookies.set() method
         kwargs = {
             'version': 0,
             'name': cookie['name'],
             'value': cookie['value'],
             'port': None,
             'port_specified': False,
             'domain': cookie['domain'],
             'domain_specified': bool(cookie['domain']),
             'domain_initial_dot': cookie['domain'].startswith('.'),
             'path': cookie['path'],
             'path_specified': bool(cookie['path']),
             'secure': cookie['secure'],
             'expires': cookie['expires'],
             'discard': True,
             'comment': None,
             'comment_url': None,
             'rest': cookie['rest'],
             'rfc2109': False,
         }
         cookie = Cookie(**kwargs)
         self.session.cookies.jar.set_cookie(cookie)
     cookies.log_cookie(self.session.cookies.jar)
     # Try access to website
     try:
         website.extract_session_data(self.get('browse'),
                                      validate=True,
                                      update_profiles=True)
     except MbrStatusAnonymousError:
         # Access not valid
         return False
     # Get the account e-mail
     page_response = self.get('your_account').decode('utf-8')
     email_match = re.search(r'account-email[^<]+>([^<]+@[^</]+)</',
                             page_response)
     email = email_match.group(1).strip() if email_match else None
     if not email:
         raise WebsiteParsingError('E-mail field not found')
     # Verify the password (with parental control api)
     try:
         response = self.post_safe('profile_hub',
                                   data={
                                       'destination':
                                       'contentRestrictions',
                                       'guid':
                                       G.LOCAL_DB.get_active_profile_guid(),
                                       'password':
                                       password,
                                       'task':
                                       'auth'
                                   })
         if response.get('status') != 'ok':
             raise LoginError(common.get_local_string(
                 12344))  # 12344=Passwords entered did not match.
     except httpx.HTTPStatusError as exc:
         if exc.response.status_code == 500:
             # This endpoint raise HTTP error 500 when the password is wrong
             raise LoginError(common.get_local_string(12344)) from exc
         raise
     common.set_credentials({'email': email, 'password': password})
     LOG.info('Login successful')
     ui.show_notification(common.get_local_string(30109))
     cookies.save(self.session.cookies.jar)
     return True