From: Art Cancro Date: Wed, 28 May 2008 21:30:13 +0000 (+0000) Subject: Added some glue code for attachment of an OpenID to X-Git-Tag: v7.86~2196 X-Git-Url: https://code.citadel.org/?p=citadel.git;a=commitdiff_plain;h=69b9292fb899d2de5bde8352ba7f11bef4fa6e8e Added some glue code for attachment of an OpenID to an existing Citadel account. --- diff --git a/webcit/Makefile.in b/webcit/Makefile.in index 8d5bdc9f4..28bbde07f 100644 --- a/webcit/Makefile.in +++ b/webcit/Makefile.in @@ -51,13 +51,13 @@ webcit: webserver.o context_loop.o ical_dezonify.o \ groupdav_main.o groupdav_get.o groupdav_propfind.o fmt_date.o \ groupdav_options.o autocompletion.o gettext.o tabs.o sieve.o \ groupdav_delete.o groupdav_put.o http_datestring.o setup_wizard.o \ - downloads.o addressbook_popup.o pushemail.o sysdep.o \ + downloads.o addressbook_popup.o pushemail.o sysdep.o openid.o \ $(LIBOBJS) $(CC) webserver.o context_loop.o cookie_conversion.o \ webcit.o auth.o tcp_sockets.o mainmenu.o serv_func.o who.o listsub.o \ roomops.o messages.o userlist.o paging.o sysmsgs.o useredit.o \ locate_host.o siteconfig.o subst.o vcard_edit.o floors.o \ - graphics.o netconf.o preferences.o html2html.o rss.o \ + graphics.o netconf.o preferences.o html2html.o rss.o openid.o \ summary.o calendar.o calendar_tools.o calendar_view.o event.o wiki.o \ availability.o ical_dezonify.o iconbar.o crypto.o inetconf.o notes.o \ groupdav_main.o groupdav_get.o groupdav_propfind.o groupdav_delete.o \ diff --git a/webcit/auth.c b/webcit/auth.c index 16bd49d80..b923dd9db 100644 --- a/webcit/auth.c +++ b/webcit/auth.c @@ -311,6 +311,7 @@ void finalize_openid_login(void) { char buf[1024]; struct wcsession *WCC = WC; + int already_logged_in = (WCC->logged_in) ; if (havebstr("openid.mode")) { if (!strcasecmp(bstr("openid.mode"), "id_res")) { @@ -340,14 +341,16 @@ void finalize_openid_login(void) // FIXME } } - else { - display_openid_login(&buf[4]); - return; - } - } } + /* If we were already logged in, this was an attempt to associate an OpenID account */ + if (already_logged_in) { + display_openids(); + return; + } + + /* Otherwise the user is probably attempting to log in using OpenID */ if (WC->logged_in) { if (WC->need_regi) { display_reg(1); diff --git a/webcit/mainmenu.c b/webcit/mainmenu.c index 4ab0eacb1..cf1ea9bf2 100644 --- a/webcit/mainmenu.c +++ b/webcit/mainmenu.c @@ -118,14 +118,16 @@ void display_main_menu(void) wprintf("" ""); - print_menu_box(_("Your info"), "adminitems", 7, + print_menu_box(_("Your info"), "adminitems", 8, "display_preferences", _("Change your preferences and settings"), "display_reg", _("Update your contact information"), "display_changepw", _("Change your password"), "display_editbio", _("Enter your 'bio'"), "display_editpic", _("Edit your online photo"), "display_sieve", _("View/edit server-side mail filters"), - "display_pushemail", _("Edit your push email settings")); + "display_pushemail", _("Edit your push email settings"), + "display_openids", _("Manage your OpenIDs") + ); wprintf(""); diff --git a/webcit/openid.c b/webcit/openid.c new file mode 100644 index 000000000..b94f0fbc3 --- /dev/null +++ b/webcit/openid.c @@ -0,0 +1,65 @@ +/* + * $Id$ + */ + +#include "webcit.h" +#include "webserver.h" + +/* + * Display the OpenIDs associated with an account + */ +void display_openids(void) +{ + output_headers(1, 1, 1, 0, 0, 0); + + wprintf("
"); + + svput("BOXTITLE", WCS_STRING, _("Manage Account/OpenID Associations")); + do_template("beginbox"); + + wprintf("FIXME -- we have to list the existing ones here"); + + wprintf("
\n"); + + wprintf("
\n"); + wprintf("\n", WC->nonce); + wprintf(_("Add an OpenID: ")); + wprintf("\n"); + wprintf("" + "
\n", _("Attach")); + do_template("endbox"); + wprintf("
"); + wDumpContent(2); +} + + +/* + * Attempt to attach an OpenID to an existing, logged-in account + */ +void openid_attach(void) { + char buf[4096]; + + if (havebstr("attach_button")) { + lprintf(CTDL_DEBUG, "Attempting to attach %s\n", bstr("openid_url")); + + snprintf(buf, sizeof buf, + "OIDS %s|%s://%s/finalize_openid_login|%s://%s", + bstr("openid_url"), + (is_https ? "https" : "http"), WC->http_host, + (is_https ? "https" : "http"), WC->http_host + ); + + serv_puts(buf); + serv_getln(buf, sizeof buf); + if (buf[0] == '2') { + lprintf(CTDL_DEBUG, "OpenID server contacted; redirecting to %s\n", &buf[4]); + http_redirect(&buf[4]); + return; + } + } + + /* If we get to this point then something failed. */ + display_openids(); +} + + diff --git a/webcit/webcit.c b/webcit/webcit.c index 77f9e9941..54ffe46b5 100644 --- a/webcit/webcit.c +++ b/webcit/webcit.c @@ -1726,7 +1726,7 @@ void session_loop(struct httprequest *req) display_openid_login(NULL); } else if ((!WC->logged_in) && (!strcasecmp(action, "openid_login"))) { do_openid_login(); - } else if ((!WC->logged_in) && (!strcasecmp(action, "finalize_openid_login"))) { + } else if (!strcasecmp(action, "finalize_openid_login")) { finalize_openid_login(); } else if (!WC->logged_in) { display_login(NULL); @@ -2088,6 +2088,10 @@ void session_loop(struct httprequest *req) download_file(index[1]); } else if (!strcasecmp(action, "upload_file")) { upload_file(); + } else if (!strcasecmp(action, "display_openids")) { + display_openids(); + } else if (!strcasecmp(action, "openid_attach")) { + openid_attach(); } /** When all else fais, display the main menu. */ diff --git a/webcit/webcit.h b/webcit/webcit.h index 5f2551484..cacacc181 100644 --- a/webcit/webcit.h +++ b/webcit/webcit.h @@ -488,6 +488,8 @@ void do_openid_login(void); void finalize_openid_login(void); void display_login(char *mesg); void display_openid_login(char *mesg); +void display_openids(void); +void openid_attach(void); void do_welcome(void); void do_logout(void); void display_main_menu(void);