Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Password Settings not Supported #79 #85

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 43 additions & 4 deletions kupfer/plugin_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,53 @@ def check_dbus_connection():
if not _has_dbus_connection:
raise ImportError(_("No D-Bus connection to desktop session"))

class UserNamePassword (object):
pass
class UserNamePassword (settings.ExtendedSetting):
''' Configuration type for storing username/password values.
Username is stored in Kupfer config, password in keyring '''
def __init__(self, obj=None):
settings.ExtendedSetting.__init__(self)
self.username = None
self.password = None
if obj:
self.username = obj.username
self.password = obj.password

def __repr__(self):
return '<UserNamePassword "%s", %s>' % (self.username,
bool(self.password))

def load(self, plugin_id, key, username):
self.password = keyring.get_password(plugin_id, username)
self.username = username

def save(self, plugin_id, key):
'''Save @user_password - store password in keyring and return username
to save in standard configuration file '''
keyring.set_password(plugin_id, self.username, self.password)
return self.username

@classmethod
def get_backend_name(cls):
return keyring.get_keyring().name


def check_keyring_support():
"""
raise ImportError with because it is not supported
Check if keyring is installed
"""
raise ImportError("Keyring is not supported")
try:
global keyring
import keyring
except ImportError:
raise ImportError("Keyring is not installed")

from keyring.backends.fail import Keyring as FailKeyring
key_storage = keyring.get_keyring()

if isinstance(key_storage, FailKeyring):
msg = "This plugin require Gnome Keyring, Kwallet or " + \
"other keyring backend to store password properly."
raise ImportError(msg)

def check_keybinding_support():
"""
Expand Down
5 changes: 1 addition & 4 deletions kupfer/ui/preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,10 +651,7 @@ def callback(widget):
setctl = settings.GetSettingsController()
val_type = plugin_support.UserNamePassword
backend_name = plugin_support.UserNamePassword.get_backend_name()
if plugin_support.UserNamePassword.is_backend_encrypted():
information = _("Using encrypted password storage: %s") % backend_name
else:
information = _("Using password storage: %s") % backend_name
information = _("Using password storage: %s") % backend_name
upass = setctl.get_plugin_config(plugin_id, key, val_type) \
or plugin_support.UserNamePassword()
user_password = ask_user_credentials(upass.username, upass.password, information)
Expand Down