Пример #1
0
 def success_cb(app_name, credentials):
     """Validation finished successfully."""
     # pylint: disable=E1101
     d = Keyring().set_credentials(app_name, credentials)
     d.addCallback(lambda _: result_cb(app_name, email))
     failure_cb = lambda f: error_cb(app_name, f.value)
     d.addErrback(failure_cb)
Пример #2
0
 def _load_proxy_creds_from_keyring(self, domain):
     """Load the proxy creds from the keyring."""
     from ubuntu_sso.keyring import Keyring
     keyring = Keyring()
     try:
         creds = yield keyring.get_credentials(str(domain))
         logger.debug('Got credentials from keyring.')
     except Exception, e:
         logger.error('Error when retrieving the creds.')
         raise WebClientError('Error when retrieving the creds.', e)
Пример #3
0
 def success_cb(app_name, credentials):
     """Login finished successfull."""
     is_validated = self.processor.is_validated(credentials)
     logger.debug('user is validated? %r.', is_validated)
     if is_validated:
         # pylint: disable=E1101
         d = Keyring().set_credentials(app_name, credentials)
         d.addCallback(lambda _: result_cb(app_name, email))
         d.addErrback(lambda failure: \
                      error_cb(app_name,
                               except_to_errdict(failure.value)))
     else:
         not_validated_cb(app_name, email)
Пример #4
0
    def _process_new_token(self, app_name, email, credentials, ping_url):
        """Process a new set of credentials for 'email'."""
        if ping_url:
            yield utils.ping_url(ping_url, email, credentials)
            logger.info('Url %r successfully opened!', ping_url)

        yield Keyring().set_credentials(app_name, credentials)
Пример #5
0
    def __init__(self, retry=False, domain=None):
        """Create a new instance."""
        super(ProxyCredsDialog, self).__init__()

        if domain is None:
            logger.debug('Domain passed as None.')
            domain = ''
        self.domain = domain
        self.keyring = Keyring()
        self.ui = Ui_ProxyCredsDialog()
        self.ui.setupUi(self)
        # lets set the different basic contents for the ui
        self._set_labels()
        self._set_buttons()
        self._set_icon()
        if retry:
            self._load_creds()
            self.ui.error_label.setVisible(True)
        else:
            self.ui.error_label.setVisible(False)
Пример #6
0
 def _load_proxy_creds_from_keyring(self, domain):
     """Load the proxy creds from the keyring."""
     from ubuntu_sso.keyring import Keyring
     keyring = Keyring()
     try:
         creds = yield keyring.get_credentials(str(domain))
         logger.debug('Got credentials from keyring.')
     except Exception as e:
         logger.error('Error when retrieving the creds.')
         raise WebClientError('Error when retrieving the creds.', e)
     if creds is not None:
         # if we are loading the same creds it means that we got the wrong
         # ones
         if (self.proxy_username == creds['username'] and
                 self.proxy_password == creds['password']):
             defer.returnValue(False)
         else:
             self.proxy_username = creds['username']
             self.proxy_password = creds['password']
             defer.returnValue(True)
     logger.debug('Proxy creds not in keyring.')
     defer.returnValue(False)
Пример #7
0
class ProxyCredsDialog(QDialog):
    """Dialog used to require the proxy credentials."""
    def __init__(self, retry=False, domain=None):
        """Create a new instance."""
        super(ProxyCredsDialog, self).__init__()

        if domain is None:
            logger.debug('Domain passed as None.')
            domain = ''
        self.domain = domain
        self.keyring = Keyring()
        self.ui = Ui_ProxyCredsDialog()
        self.ui.setupUi(self)
        # lets set the different basic contents for the ui
        self._set_labels()
        self._set_buttons()
        self._set_icon()
        if retry:
            self._load_creds()
            self.ui.error_label.setVisible(True)
        else:
            self.ui.error_label.setVisible(False)

    @defer.inlineCallbacks
    def _load_creds(self):
        """Tries to load the creds in a retry event."""
        # pylint: disable=W0703
        try:
            creds = yield self.keyring.get_credentials(self.domain)
            if creds is not None:
                logger.debug('Go no empty credentials.')
                # lets set the text for the inputs
                self.ui.username_entry.setText(creds['username'])
                self.ui.password_entry.setText(creds['password'])
        except Exception:
            logger.error('Problem getting old creds.')
        # pylint: enable=W0703

    def _set_labels(self):
        """Set the labels translations."""
        self.setWindowTitle(PROXY_CREDS_DIALOG_TITLE)
        self.ui.title_label.setText(PROXY_CREDS_HEADER)
        self.ui.explanation_label.setText(PROXY_CREDS_EXPLANATION)
        self.ui.connection_label.setText(PROXY_CREDS_CONNECTION)
        # HACK: later this should be set using qss
        self.ui.error_label.setText("<font color='#a62626'><b>%s</b></font>" %
                                    PROXY_CREDS_ERROR)
        self.ui.username_label.setText(PROXY_CREDS_USER_LABEL)
        self.ui.password_label.setText(PROXY_CREDS_PSWD_LABEL)
        self.ui.domain_label.setText(self.domain)

    @defer.inlineCallbacks
    def _on_save_clicked(self, *args):
        """Save the new credentials."""
        username = compat.text_type(
            self.ui.username_entry.text()).encode('utf8')
        password = compat.text_type(
            self.ui.password_entry.text()).encode('utf8')
        creds = dict(username=username, password=password)
        try:
            logger.debug('Save credentials as for domain %s.', self.domain)
            yield self.keyring.set_credentials(self.domain, creds)
        except Exception as e:
            logger.exception('Could not set credentials: %s', e)
            self.done(EXCEPTION_RAISED)
        logger.debug('Stored creds')
        self.done(USER_SUCCESS)

    def _on_cancel_clicked(self, *args):
        """End the dialog."""
        logger.debug('User canceled credentials dialog.')
        self.done(USER_CANCELLATION)

    def _set_buttons(self):
        """Set the labels of the buttons."""
        self.ui.help_button.setText(PROXY_CREDS_HELP_BUTTON)
        self.ui.cancel_button.setText(CANCEL_BUTTON)
        self.ui.cancel_button.clicked.connect(self._on_cancel_clicked)
        self.ui.save_button.setText(PROXY_CREDS_SAVE_BUTTON)
        self.ui.save_button.clicked.connect(self._on_save_clicked)

    def _set_icon(self):
        """Set the icon used in the dialog."""
        icon = QIcon.fromTheme('gtk-dialog-authentication')
        self.ui.logo_label.setText('')
        self.ui.logo_label.setPixmap(icon.pixmap(48, 48))