Commit f00270ad authored by Florian Müllner's avatar Florian Müllner
Browse files

utils: Add helper methods to lookup/store identify passwords

When we offer users to handle NickServ identification for them
we need to lookup and store the password, so add keyring helpers
just like the ones we use for server passwords:

https://bugzilla.gnome.org/show_bug.cgi?id=709982
parent 37b69b37
......@@ -31,10 +31,14 @@ const Tp = imports.gi.TelepathyGLib;
const AppNotifications = imports.appNotifications;
const Signals = imports.signals;
const SECRET_SCHEMA = new Secret.Schema(
const SECRET_SCHEMA_ACCOUNT = new Secret.Schema(
'org.gnome.Polari.Account', Secret.SchemaFlags.NONE,
{ 'account-id': Secret.SchemaAttributeType.STRING }
);
const SECRET_SCHEMA_IDENTIFY = new Secret.Schema(
'org.gnome.Polari.Identify', Secret.SchemaFlags.NONE,
{ 'account-id': Secret.SchemaAttributeType.STRING }
);
const GPASTE_BASEURL = 'https://paste.gnome.org/';
......@@ -117,9 +121,18 @@ function getTpEventTime() {
}
function storeAccountPassword(account, password, callback) {
let attr = { 'account-id': account.get_path_suffix() };
let label = _("Polari server password for %s").format(account.display_name);
Secret.password_store(SECRET_SCHEMA, attr, Secret.COLLECTION_DEFAULT,
_storePassword(SECRET_SCHEMA_ACCOUNT, label, account, password, callback);
}
function storeIdentifyPassword(account, password, callback) {
let label = _("Polari NickServ password for %s").format(account.display_name);
_storePassword(SECRET_SCHEMA_IDENTIFY, label, account, password, callback);
}
function _storePassword(schema, label, account, password, callback) {
let attr = { 'account-id': account.get_path_suffix() };
Secret.password_store(schema, attr, Secret.COLLECTION_DEFAULT,
label, password, null,
function(o, res) {
try {
......@@ -134,8 +147,16 @@ function storeAccountPassword(account, password, callback) {
}
function lookupAccountPassword(account, callback) {
_lookupPassword(SECRET_SCHEMA_ACCOUNT, account, callback);
}
function lookupIdentifyPassword(account, callback) {
_lookupPassword(SECRET_SCHEMA_IDENTIFY, account, callback);
}
function _lookupPassword(schema, account, callback) {
let attr = { 'account-id': account.get_path_suffix() };
Secret.password_lookup(SECRET_SCHEMA, attr, null,
Secret.password_lookup(schema, attr, null,
function(o, res) {
try {
let password = Secret.password_lookup_finish(res);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment