diff options
author | Kali Kaneko <kali@leap.se> | 2013-11-05 11:41:27 -0200 |
---|---|---|
committer | Kali Kaneko <kali@leap.se> | 2013-11-05 11:41:27 -0200 |
commit | 603385e3f539e382077e8681cdd2477a7e0733ea (patch) | |
tree | 1d6d8f3e6e18d6d0d0fb3f629ab131f2dd366980 /src/leap/bitmask/gui/login.py | |
parent | a6d8eb70ed15ab339d695eacd3cae58a2e561ba8 (diff) | |
parent | 23e9034664edf6b2a01a677c4fa4e6efd880e364 (diff) |
Merge tag '0.3.6' into debian
Tag leap.bitmask version 0.3.6
Diffstat (limited to 'src/leap/bitmask/gui/login.py')
-rw-r--r-- | src/leap/bitmask/gui/login.py | 47 |
1 files changed, 44 insertions, 3 deletions
diff --git a/src/leap/bitmask/gui/login.py b/src/leap/bitmask/gui/login.py index ac34fe23..b21057f0 100644 --- a/src/leap/bitmask/gui/login.py +++ b/src/leap/bitmask/gui/login.py @@ -49,6 +49,9 @@ class LoginWidget(QtGui.QWidget): BARE_USERNAME_REGEX = r"^[A-Za-z\d_]+$" + # Keyring + KEYRING_KEY = "bitmask" + def __init__(self, settings, parent=None): """ Constructs the LoginWidget. @@ -168,7 +171,7 @@ class LoginWidget(QtGui.QWidget): """ Returns the user that appears in the widget. - :rtype: str + :rtype: unicode """ return self.ui.lnUser.text() @@ -177,7 +180,7 @@ class LoginWidget(QtGui.QWidget): Sets the password for the widget :param password: password to set - :type password: str + :type password: unicode """ self.ui.lnPassword.setText(password) @@ -185,7 +188,7 @@ class LoginWidget(QtGui.QWidget): """ Returns the password that appears in the widget - :rtype: str + :rtype: unicode """ return self.ui.lnPassword.text() @@ -366,3 +369,41 @@ class LoginWidget(QtGui.QWidget): self.ui.btnLogout.setText(self.tr("Logout")) self.ui.btnLogout.setEnabled(True) self.ui.clblErrorMsg.hide() + + def load_user_from_keyring(self, saved_user): + """ + Tries to load a user from the keyring, returns True if it was + loaded successfully, False otherwise. + + :param saved_user: String containing the saved username as + user@domain + :type saved_user: unicode + + :rtype: bool + """ + leap_assert_type(saved_user, unicode) + + try: + username, domain = saved_user.split('@') + except ValueError as e: + # if the saved_user does not contain an '@' + logger.error('Username@provider malformed. %r' % (e, )) + return False + + self.set_user(username) + + self.set_remember(True) + + saved_password = None + try: + saved_password = keyring.get_password(self.KEYRING_KEY, + saved_user + .encode("utf8")) + except ValueError as e: + logger.debug("Incorrect Password. %r." % (e,)) + + if saved_password is not None: + self.set_password(saved_password) + return True + + return False |