diff options
author | Chris Toshok <toshok@ximian.com> | 2002-09-12 06:08:40 +0800 |
---|---|---|
committer | Chris Toshok <toshok@src.gnome.org> | 2002-09-12 06:08:40 +0800 |
commit | 64d454a16c99af0418fbf31e7b6ba070ace6535e (patch) | |
tree | 6316ce78200663f4c010d4785a1290f24bbc918f /addressbook/gui/component | |
parent | 9b1732a7825e666762c979da7428019eeb9f1aa4 (diff) | |
download | gsoc2013-evolution-64d454a16c99af0418fbf31e7b6ba070ace6535e.tar.gz gsoc2013-evolution-64d454a16c99af0418fbf31e7b6ba070ace6535e.tar.zst gsoc2013-evolution-64d454a16c99af0418fbf31e7b6ba070ace6535e.zip |
[ fixes #30208 ] if the user clicked cancel in the password dialog, let
2002-09-11 Chris Toshok <toshok@ximian.com>
[ fixes #30208 ]
* gui/component/addressbook.c (load_uri_auth_cb): if the user
clicked cancel in the password dialog, let them off the hook and
bind anonymously. Otherwise (if they failed to auth), prompt them
for the password again.
(addressbook_authenticate): new function, split out 99% of the
auth machinery here so it can be called multiple times. Also,
call the callback with E_BOOK_STATUS_CANCELLED if the user clicked
the cancel button in the dialog.
(load_uri_cb): call addressbook_authenticate if the book has auth
enabled.
(addressbook_load_uri): use g_new0.
svn path=/trunk/; revision=18049
Diffstat (limited to 'addressbook/gui/component')
-rw-r--r-- | addressbook/gui/component/addressbook.c | 153 |
1 files changed, 97 insertions, 56 deletions
diff --git a/addressbook/gui/component/addressbook.c b/addressbook/gui/component/addressbook.c index 6169dd5753..23997a9984 100644 --- a/addressbook/gui/component/addressbook.c +++ b/addressbook/gui/component/addressbook.c @@ -72,6 +72,9 @@ typedef struct { static void addressbook_view_ref (AddressbookView *); static void addressbook_view_unref (AddressbookView *); +static void addressbook_authenticate (EBook *book, gboolean previous_failure, + AddressbookSource *source, EBookCallback cb, gpointer closure); + static void save_contact_cb (BonoboUIComponent *uih, void *user_data, const char *path) { @@ -563,6 +566,8 @@ get_prop (BonoboPropertyBag *bag, typedef struct { EBookCallback cb; + char *clean_uri; + AddressbookSource *source; gpointer closure; } LoadUriData; @@ -572,15 +577,95 @@ load_uri_auth_cb (EBook *book, EBookStatus status, gpointer closure) LoadUriData *data = closure; if (status != E_BOOK_STATUS_SUCCESS) { - /* pop up a nice dialog, or redo the authentication - bit some number of times. */ + if (status == E_BOOK_STATUS_CANCELLED) { + /* the user clicked cancel in the password dialog */ + gnome_warning_dialog (_("Accessing LDAP Server anonymously")); + data->cb (book, E_BOOK_STATUS_SUCCESS, data->closure); + g_free (data->clean_uri); + g_free (data); + return; + } + else { + e_passwords_forget_password (data->clean_uri); + addressbook_authenticate (book, TRUE, data->source, load_uri_auth_cb, closure); + return; + } } data->cb (book, status, data->closure); + g_free (data->clean_uri); g_free (data); } +static void +addressbook_authenticate (EBook *book, gboolean previous_failure, AddressbookSource *source, + EBookCallback cb, gpointer closure) +{ + LoadUriData *load_uri_data = closure; + const char *password; + char *pass_dup = NULL; + char *semicolon; + + load_uri_data->clean_uri = g_strdup (e_book_get_uri (book)); + + semicolon = strchr (load_uri_data->clean_uri, ';'); + + if (semicolon) + *semicolon = '\0'; + + password = e_passwords_get_password (load_uri_data->clean_uri); + + if (!password) { + char *prompt; + gboolean remember; + char *failed_auth; + + if (previous_failure) { + failed_auth = _("Failed to authenticate.\n"); + } + else { + failed_auth = ""; + } + + + if (source->auth == ADDRESSBOOK_LDAP_AUTH_SIMPLE_BINDDN) + prompt = g_strdup_printf (_("%sEnter password for %s (user %s)"), + failed_auth, source->name, source->binddn); + else + prompt = g_strdup_printf (_("%sEnter password for %s (user %s)"), + failed_auth, source->name, source->email_addr); + remember = source->remember_passwd; + pass_dup = e_passwords_ask_password (prompt, load_uri_data->clean_uri, prompt, TRUE, + E_PASSWORDS_REMEMBER_FOREVER, &remember, + NULL); + if (remember != source->remember_passwd) { + source->remember_passwd = remember; + addressbook_storage_write_sources (); + } + g_free (prompt); + } + + if (password || pass_dup) { + char *user; + + if (source->auth == ADDRESSBOOK_LDAP_AUTH_SIMPLE_BINDDN) + user = source->binddn; + else + user = source->email_addr; + if (!user) + user = ""; + e_book_authenticate_user (book, user, password ? password : pass_dup, + addressbook_storage_auth_type_to_string (source->auth), + cb, closure); + g_free (pass_dup); + return; + } + else { + /* they hit cancel */ + cb (book, E_BOOK_STATUS_CANCELLED, closure); + } +} static void load_uri_cb (EBook *book, EBookStatus status, gpointer closure) @@ -588,65 +673,21 @@ load_uri_cb (EBook *book, EBookStatus status, gpointer closure) LoadUriData *load_uri_data = closure; if (status == E_BOOK_STATUS_SUCCESS && book != NULL) { - AddressbookSource *source; /* check if the addressbook needs authentication */ - source = addressbook_storage_get_source_by_uri (e_book_get_uri (book)); - if (source && - source->auth != ADDRESSBOOK_LDAP_AUTH_NONE) { - const char *password; - char *pass_dup = NULL; - char *uri = g_strdup (e_book_get_uri (book)); - char *semicolon = strchr (uri, ';'); - - if (semicolon) - *semicolon = '\0'; - - password = e_passwords_get_password (uri); - - if (!password) { - char *prompt; - gboolean remember; - - if (source->auth == ADDRESSBOOK_LDAP_AUTH_SIMPLE_BINDDN) - prompt = g_strdup_printf (_("Enter password for %s (user %s)"), - source->name, source->binddn); - else - prompt = g_strdup_printf (_("Enter password for %s (user %s)"), - source->name, source->email_addr); - remember = source->remember_passwd; - pass_dup = e_passwords_ask_password ( - prompt, uri, prompt, TRUE, - E_PASSWORDS_REMEMBER_FOREVER, &remember, - NULL); - if (remember != source->remember_passwd) { - source->remember_passwd = remember; - addressbook_storage_write_sources (); - } - g_free (prompt); - } + load_uri_data->source = addressbook_storage_get_source_by_uri (e_book_get_uri (book)); - g_free (uri); - - if (password || pass_dup) { - char *user; - - if (source->auth == ADDRESSBOOK_LDAP_AUTH_SIMPLE_BINDDN) - user = source->binddn; - else - user = source->email_addr; - if (!user) - user = ""; - e_book_authenticate_user (book, user, password ? password : pass_dup, - addressbook_storage_auth_type_to_string (source->auth), - load_uri_auth_cb, closure); - g_free (pass_dup); - return; - } + if (load_uri_data->source && + load_uri_data->source->auth != ADDRESSBOOK_LDAP_AUTH_NONE) { + + addressbook_authenticate (book, FALSE, load_uri_data->source, + load_uri_auth_cb, closure); + + return; } } - + load_uri_data->cb (book, status, load_uri_data->closure); g_free (load_uri_data); } @@ -655,7 +696,7 @@ gboolean addressbook_load_uri (EBook *book, const char *uri, EBookCallback cb, gpointer closure) { - LoadUriData *load_uri_data = g_new (LoadUriData, 1); + LoadUriData *load_uri_data = g_new0 (LoadUriData, 1); gboolean rv; load_uri_data->cb = cb; |