def _prefetch_login(self):
     """Check if we have stored credentials.
     If so, do the login before the user requests it"""
     try:
         common.get_credentials()
         if not self._is_logged_in():
             self._login()
     except MissingCredentialsError:
         common.info('Login prefetch: No stored credentials are available')
     except LoginFailedError:
         ui.show_notification(common.get_local_string(30009))
 def _prefetch_login(self):
     """Check if we have stored credentials.
     If so, do the login before the user requests it"""
     try:
         common.get_credentials()
         if not self._is_logged_in():
             self._login()
         else:
             self.set_session_header_data()
     except MissingCredentialsError:
         common.info('Login prefetch: No stored credentials are available')
     except (LoginFailedError, LoginValidateError):
         ui.show_notification(common.get_local_string(30009))
     except InvalidMembershipStatusError:
         ui.show_notification(common.get_local_string(30180), time=10000)
 def _add_auth_info(self, header_data, auth_data):
     """User authentication identifies the application user associated with a message"""
     # Warning: the user id token contains also contains the identity of the netflix profile
     # therefore it is necessary to use the right user id token for the request
     if auth_data.get('user_id_token'):
         if auth_data['use_switch_profile']:
             # The SWITCH_PROFILE is a custom Netflix MSL user authentication scheme
             # that is needed for switching profile on MSL side
             # works only combined with user id token and can not be used with all endpoints
             # after use it you will get user id token of the profile specified in the response
             header_data['userauthdata'] = {
                 'scheme': 'SWITCH_PROFILE',
                 'authdata': {
                     'useridtoken': auth_data['user_id_token'],
                     'profileguid': G.LOCAL_DB.get_active_profile_guid()
                 }
             }
         else:
             # Authentication with user ID token containing the user identity (netflix profile)
             header_data['useridtoken'] = auth_data['user_id_token']
     else:
         # Authentication with the user credentials
         credentials = common.get_credentials()
         header_data['userauthdata'] = {
             'scheme': 'EMAIL_PASSWORD',
             'authdata': {
                 'email': credentials['email'],
                 'password': credentials['password']
             }
         }
Example #4
0
 def _login(self, modal_error_message=False):
     """Perform account login"""
     # If exists get the current esn value before extract a new session data
     current_esn = g.get_esn()
     try:
         # First we get the authentication url without logging in, required for login API call
         react_context = website.extract_json(self._get('login'), 'reactContext')
         auth_url = website.extract_api_data(react_context)['auth_url']
         common.debug('Logging in...')
         login_response = self._post(
             'login',
             data=_login_payload(common.get_credentials(), auth_url))
         try:
             website.extract_session_data(login_response, validate=True, update_profiles=True)
             common.info('Login successful')
             ui.show_notification(common.get_local_string(30109))
             self.update_session_data(current_esn)
             return True
         except (LoginValidateError, LoginValidateErrorIncorrectPassword) as exc:
             self.session.cookies.clear()
             common.purge_credentials()
             if not modal_error_message:
                 raise
             ui.show_ok_dialog(common.get_local_string(30008), unicode(exc))
     except InvalidMembershipStatusError:
         ui.show_error_info(common.get_local_string(30008),
                            common.get_local_string(30180),
                            False, True)
     except Exception:  # pylint: disable=broad-except
         import traceback
         common.error(g.py2_decode(traceback.format_exc(), 'latin-1'))
         self.session.cookies.clear()
         raise
     return False
Example #5
0
    def login(self, credentials=None):
        """Perform account login"""
        try:
            # First we get the authentication url without logging in, required for login API call
            react_context = website.extract_json(self.get('login'), 'reactContext')
            auth_url = website.extract_api_data(react_context)['auth_url']
            LOG.debug('Logging in...')
            login_response = self.post(
                'login',
                headers={'Accept-Language': _get_accept_language_string(react_context)},
                data=_login_payload(credentials or common.get_credentials(), auth_url, react_context))

            website.extract_session_data(login_response, validate=True, update_profiles=True)
            if credentials:
                # Save credentials only when login has succeeded
                common.set_credentials(credentials)
            LOG.info('Login successful')
            ui.show_notification(common.get_local_string(30109))
            cookies.save(self.account_hash, self.session.cookies)
            return True
        except LoginValidateError as exc:
            self.session.cookies.clear()
            common.purge_credentials()
            raise_from(LoginError(unicode(exc)), exc)
        except (MbrStatusNeverMemberError, MbrStatusFormerMemberError) as exc:
            self.session.cookies.clear()
            LOG.warn('Membership status {} not valid for login', exc)
            raise_from(LoginError(common.get_local_string(30180)), exc)
        except Exception:  # pylint: disable=broad-except
            self.session.cookies.clear()
            import traceback
            LOG.error(G.py2_decode(traceback.format_exc(), 'latin-1'))
            raise
Example #6
0
 def _login(self, modal_error_message=False):
     """Perform account login"""
     # If exists get the current esn value before extract a new session data
     current_esn = g.get_esn()
     try:
         # First we get the authentication url without logging in, required for login API call
         react_context = website.extract_json(self._get('profiles'),
                                              'reactContext')
         auth_url = website.extract_api_data(react_context)['auth_url']
         common.debug('Logging in...')
         login_response = self._post('login',
                                     data=_login_payload(
                                         common.get_credentials(),
                                         auth_url))
         validate_msg = website.validate_login(login_response)
         if validate_msg:
             self.session.cookies.clear()
             common.purge_credentials()
             if modal_error_message:
                 ui.show_ok_dialog(common.get_local_string(30008),
                                   validate_msg)
             else:
                 ui.show_notification(common.get_local_string(30009))
             return False
         website.extract_session_data(login_response)
     except Exception as exc:
         common.error(traceback.format_exc())
         self.session.cookies.clear()
         raise exc
     common.info('Login successful')
     ui.show_notification(common.get_local_string(30109))
     self.update_session_data(current_esn)
     return True
Example #7
0
 def prefetch_login(self):
     """Check if we have stored credentials.
     If so, do the login before the user requests it"""
     from requests import exceptions
     try:
         common.get_credentials()
         if not self.is_logged_in():
             self.login(modal_error_message=False)
         return True
     except exceptions.RequestException as exc:
         # It was not possible to connect to the web service, no connection, network problem, etc
         import traceback
         LOG.error('Login prefetch: request exception {}', exc)
         LOG.debug(G.py2_decode(traceback.format_exc(), 'latin-1'))
     except Exception as exc:  # pylint: disable=broad-except
         LOG.warn('Login prefetch: failed {}', exc)
     return False
Example #8
0
 def prefetch_login(self):
     """Check if we have stored credentials.
     If so, do the login before the user requests it"""
     try:
         common.get_credentials()
         if not self.is_logged_in():
             self.login()
         return True
     except MissingCredentialsError:
         pass
     except httpx.RequestError as exc:
         # It was not possible to connect to the web service, no connection, network problem, etc
         import traceback
         LOG.error('Login prefetch: request exception {}', exc)
         LOG.debug(traceback.format_exc())
     except Exception as exc:  # pylint: disable=broad-except
         LOG.warn('Login prefetch: failed {}', exc)
     return False
Example #9
0
 def _prefetch_login(self):
     """Check if we have stored credentials.
     If so, do the login before the user requests it"""
     try:
         common.get_credentials()
         if not self._is_logged_in():
             self._login()
         self.is_prefetch_login = True
     except requests.exceptions.RequestException as exc:
         # It was not possible to connect to the web service, no connection, network problem, etc
         import traceback
         common.error('Login prefetch: request exception {}', exc)
         common.debug(traceback.format_exc())
     except MissingCredentialsError:
         common.info('Login prefetch: No stored credentials are available')
     except (LoginFailedError, LoginValidateError):
         ui.show_notification(common.get_local_string(30009))
     except InvalidMembershipStatusError:
         ui.show_notification(common.get_local_string(30180), time=10000)
Example #10
0
def _add_auth_info(header_data, tokens):
    if 'usertoken' not in tokens:
        credentials = common.get_credentials()
        # Auth via email and password
        header_data['userauthdata'] = {
            'scheme': 'EMAIL_PASSWORD',
            'authdata': {
                'email': credentials['email'],
                'password': credentials['password']
            }
        }
Example #11
0
def set_parental_control_data(data):
    """Set the parental control data"""
    try:
        return common.make_call(
            'post',
            {'component': 'pin_service',
             'data': {'maturityLevel': data['maturity_level'],
                      'password': common.get_credentials().get('password'),
                      'pin': data['pin']}}
        )
    except Exception:  # pylint: disable=broad-except
        return {}
def _add_auth_info(header_data, user_id_token):
    """User authentication identifies the application user associated with a message"""
    if user_id_token and _is_useridtoken_valid(user_id_token):
        # Authentication with user ID token containing the user identity
        header_data['useridtoken'] = user_id_token
    else:
        # Authentication with the user credentials
        credentials = common.get_credentials()
        header_data['userauthdata'] = {
            'scheme': 'EMAIL_PASSWORD',
            'authdata': {
                'email': credentials['email'],
                'password': credentials['password']
            }
        }
Example #13
0
 def prefetch_login(self):
     """Check if we have stored credentials.
     If so, do the login before the user requests it"""
     try:
         common.get_credentials()
         if not self.is_logged_in():
             self._login()
         else:
             # A hack way to full load requests module without blocking the service startup
             common.send_signal(signal='startup_requests_module',
                                non_blocking=True)
         self.is_prefetch_login = True
     except requests.exceptions.RequestException as exc:
         # It was not possible to connect to the web service, no connection, network problem, etc
         import traceback
         common.error('Login prefetch: request exception {}', exc)
         common.debug(g.py2_decode(traceback.format_exc(), 'latin-1'))
     except MissingCredentialsError:
         common.info('Login prefetch: No stored credentials are available')
     except (LoginFailedError, LoginValidateError):
         ui.show_notification(common.get_local_string(30009))
     except (InvalidMembershipStatusError,
             InvalidMembershipStatusAnonymous):
         ui.show_notification(common.get_local_string(30180), time=10000)
Example #14
0
    def _login(self):
        """Perform account login"""
        try:
            auth_url = website.extract_userdata(
                self._get('profiles'))['authURL']
            common.debug('Logging in...')
            login_response = self._post(
                'login',
                data=_login_payload(common.get_credentials(), auth_url))
            session_data = website.extract_session_data(login_response)
        except Exception:
            common.debug(traceback.format_exc())
            self.session.cookies.clear()
            raise LoginFailedError

        common.info('Login successful')
        ui.show_notification(common.get_local_string(30109))
        self.session_data = session_data
Example #15
0
 def login(self, modal_error_message=True):
     """Perform account login"""
     try:
         # First we get the authentication url without logging in, required for login API call
         react_context = website.extract_json(self.get('login'),
                                              'reactContext')
         auth_url = website.extract_api_data(react_context)['auth_url']
         LOG.debug('Logging in...')
         login_response = self.post('login',
                                    data=_login_payload(
                                        common.get_credentials(), auth_url))
         try:
             website.extract_session_data(login_response,
                                          validate=True,
                                          update_profiles=True)
             LOG.info('Login successful')
             ui.show_notification(common.get_local_string(30109))
             cookies.save(self.account_hash, self.session.cookies)
             return True
         except LoginValidateError as exc:
             self.session.cookies.clear()
             common.purge_credentials()
             if not modal_error_message:
                 raise
             ui.show_ok_dialog(common.get_local_string(30008), unicode(exc))
         except (MbrStatusNeverMemberError, MbrStatusFormerMemberError):
             if not modal_error_message:
                 raise
             ui.show_error_info(common.get_local_string(30008),
                                common.get_local_string(30180), False, True)
     except Exception:  # pylint: disable=broad-except
         import traceback
         LOG.error(G.py2_decode(traceback.format_exc(), 'latin-1'))
         self.session.cookies.clear()
         raise
     return False
Example #16
0
 def account_hash(self):
     """The unique hash of the current account"""
     return urlsafe_b64encode(common.get_credentials().get(
         'email', 'NoMail'))
Example #17
0
 def account_hash(self):
     """The unique hash of the current account"""
     from base64 import urlsafe_b64encode
     return urlsafe_b64encode(common.get_credentials().get(
         'email', 'NoMail').encode('utf-8')).decode('utf-8')