Beispiel #1
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
Beispiel #2
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
    def activate_profile(self, guid):
        """Set the profile identified by guid as active"""
        common.debug('Switching to profile {}', guid)
        response = self._get('switch_profile', params={'tkn': guid})
        react_context = website.extract_json(response, 'reactContext')
        self.auth_url = website.extract_api_data(react_context)['auth_url']

        # if guid != g.LOCAL_DB.get_active_profile_guid():
        #     common.info('Activating profile {}', guid)
        #     self._get(component='activate_profile',
        #               req_type='api',
        #               params={'switchProfileGuid': guid,
        #                       '_': int(time.time()),
        #                       'authURL': self.auth_url})

        g.LOCAL_DB.switch_active_profile(guid)
        self.update_session_data()
Beispiel #4
0
 def activate_profile(self, guid):
     """Set the profile identified by guid as active"""
     common.debug('Activating profile {}'.format(guid))
     if guid == g.LOCAL_DB.get_active_profile_guid():
         common.debug('Profile {} is already active'.format(guid))
         return False
     self._get(component='activate_profile',
               req_type='api',
               params={
                   'switchProfileGuid': guid,
                   '_': int(time.time()),
                   'authURL': self.auth_url
               })
     # When switch profile is performed the authURL change
     react_context = website.extract_json(self._get('browse'),
                                          'reactContext')
     self.auth_url = website.extract_api_data(react_context)['auth_url']
     g.LOCAL_DB.switch_active_profile(guid)
     self.update_session_data()
     common.debug('Successfully activated profile {}'.format(guid))
     return True
 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']
         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))
             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
         common.error(G.py2_decode(traceback.format_exc(), 'latin-1'))
         self.session.cookies.clear()
         raise
     return False