예제 #1
0
 def login(self, app_name, args):
     """Get credentials if found else prompt GUI to login."""
     self.ref_count += 1
     obj = Credentials(app_name, **self._parse_args(args))
     d = obj.login()
     d.addCallback(lambda creds: self.CredentialsFound(app_name, creds))
     d.addErrback(self._process_failures, app_name)
예제 #2
0
    def login_email_password(self, app_name, args):
        """Get credentials if found else try to login.

        Login will be done by inspecting 'args' and expecting to find two keys:
        'email' and 'password'.

        """
        self.ref_count += 1
        email = args.pop('email')
        password = args.pop('password')
        obj = Credentials(app_name, **self._parse_args(args))
        d = obj.login(email=email, password=password)
        d.addCallback(lambda creds: self.CredentialsFound(app_name, creds))
        d.addErrback(self._process_failures, app_name)
예제 #3
0
    def clear_credentials(self, app_name, args):
        """Clear the credentials for an application.

        - 'app_name': the name of the application which credentials are
        going to be removed.

        - 'args' is a dictionary, currently not used.

        """
        self.ref_count += 1
        obj = Credentials(app_name)
        d = obj.clear_credentials()
        d.addCallback(lambda _: self.CredentialsCleared(app_name))
        d.addErrback(lambda f: self.CredentialsError(app_name, f.value))
예제 #4
0
    def store_credentials(self, app_name, args):
        """Store the token for an application.

        - 'app_name': the name of the application which credentials are
        going to be stored.

        - 'args' is the dictionary holding the credentials. Needs to provide
        the following mandatory keys: 'token', 'token_key', 'consumer_key',
        'consumer_secret'.

        """
        self.ref_count += 1
        obj = Credentials(app_name)
        d = obj.store_credentials(args)
        d.addCallback(lambda _: self.CredentialsStored(app_name))
        d.addErrback(lambda f: self.CredentialsError(app_name, f.value))
예제 #5
0
    def find_credentials(self, app_name, args, success_cb=None, error_cb=None):
        """Look for the credentials for an application.

        - 'app_name': the name of the application which credentials are
        going to be removed.

        - 'args' is a dictionary, currently not used.

        - 'success_cb', if not None, will be executed if the operation was
        a success.

        - 'error_cb', if not None, will be executed if the operation had
        an error.

        """
        def _analize_creds(credentials):
            """Find credentials and notify using signals."""
            if credentials is not None and len(credentials) > 0:
                self.CredentialsFound(app_name, credentials)
            else:
                self.CredentialsNotFound(app_name)

        def _tweaked_success_cb(creds):
            """Decrease ref counter and call 'success_cb'."""
            self.ref_count -= 1
            success_cb(creds)

        if success_cb is None:
            _success_cb = _analize_creds
        else:
            _success_cb = _tweaked_success_cb

        def _tweaked_error_cb(error, app):
            """Decrease ref counter and call 'error_cb', modifying the dict."""
            self.ref_count -= 1
            error_cb(except_to_errdict(error.value))

        if error_cb is None:
            _error_cb = lambda f, _: self.CredentialsError(app_name, f.value)
        else:
            _error_cb = _tweaked_error_cb

        self.ref_count += 1
        obj = Credentials(app_name)
        d = obj.find_credentials()
        d.addCallback(_success_cb)
        d.addErrback(_error_cb, app_name)