Commit 58110dd4 authored by Michael Gratton's avatar Michael Gratton 🤞 Committed by Michael Gratton

Handle un-remembered passwords properly

Ensure that when the pref for non remembering passwords is changed, that
the account's config is updated. When not rememebering the password,
clear it from the controller instead of the libsecret mediator so its
obvious what's going on, and when updating creds in the mediator return
true if a password is present, so they don't cause an immediate auth
error.
parent cd10cd7c
Pipeline #65760 passed with stages
in 42 minutes and 7 seconds
......@@ -773,8 +773,6 @@ public class GearyController : Geary.BaseObject {
credentials
);
if (password_dialog.run()) {
service.remember_password = password_dialog.remember_password;
// The update the credentials for the service that the
// credentials actually came from
Geary.ServiceInformation creds_service =
......@@ -785,14 +783,27 @@ public class GearyController : Geary.BaseObject {
password_dialog.password
);
// Update the remember password pref if changed
bool remember = password_dialog.remember_password;
if (creds_service.remember_password != remember) {
creds_service.remember_password = remember;
account.changed();
}
SecretMediator libsecret = (SecretMediator) account.mediator;
try {
// Update the secret using the service where the
// credentials originated, since the service forms
// part of the key's identity
yield libsecret.update_token(
account, creds_service, context.cancellable
);
if (creds_service.remember_password) {
yield libsecret.update_token(
account, creds_service, context.cancellable
);
} else {
yield libsecret.clear_token(
account, creds_service, context.cancellable
);
}
} catch (GLib.IOError.CANCELLED err) {
// all good
} catch (GLib.Error err) {
......@@ -805,6 +816,7 @@ public class GearyController : Geary.BaseObject {
)
);
}
context.authentication_attempts++;
} else {
// User cancelled, bail out unconditionally
......
......@@ -46,19 +46,25 @@ public class SecretMediator : Geary.CredentialsMediator, Object {
Cancellable? cancellable)
throws GLib.Error {
bool loaded = false;
if (service.credentials != null && service.remember_password) {
string? password = yield Secret.password_lookupv(
SecretMediator.schema, new_attrs(service), cancellable
);
if (service.credentials != null) {
if (service.remember_password) {
string? password = yield Secret.password_lookupv(
SecretMediator.schema, new_attrs(service), cancellable
);
if (password == null) {
password = yield migrate_old_password(service, cancellable);
}
if (password == null) {
password = yield migrate_old_password(service, cancellable);
}
if (password != null) {
service.credentials =
if (password != null) {
service.credentials =
service.credentials.copy_with_token(password);
loaded = true;
loaded = true;
}
} else {
// Not remembering the password, so just make sure it
// has been filled in
loaded = service.credentials.is_complete();
}
}
......@@ -68,20 +74,9 @@ public class SecretMediator : Geary.CredentialsMediator, Object {
public async void update_token(Geary.AccountInformation account,
Geary.ServiceInformation service,
Cancellable? cancellable)
throws Error {
if (service.credentials != null && service.remember_password) {
try {
yield do_store(service, service.credentials.token, cancellable);
} catch (Error e) {
debug(
"Unable to store libsecret password for %s: %s %s",
account.id,
to_proto_value(service.protocol),
service.credentials.user
);
}
} else {
yield clear_token(account, service, cancellable);
throws GLib.Error {
if (service.credentials != null) {
yield do_store(service, service.credentials.token, cancellable);
}
}
......
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