Added some glue code for attachment of an OpenID to
authorArt Cancro <ajc@citadel.org>
Wed, 28 May 2008 21:30:13 +0000 (21:30 +0000)
committerArt Cancro <ajc@citadel.org>
Wed, 28 May 2008 21:30:13 +0000 (21:30 +0000)
an existing Citadel account.

webcit/Makefile.in
webcit/auth.c
webcit/mainmenu.c
webcit/openid.c [new file with mode: 0644]
webcit/webcit.c
webcit/webcit.h

index 8d5bdc9f456c439fb2f15c9022c975d80ebd6916..28bbde07ff5451b5b9db1ac423c2da8052697b78 100644 (file)
@@ -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 \
index 16bd49d804525b35c7ad628059ae6ff0f6ef0ba8..b923dd9dbdbcd77f172b7e91ebcd325e1339fc1e 100644 (file)
@@ -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);
index 4ab0eacb18485e5c6c07bde37264f2e6fd514ec2..cf1ea9bf2abeef28daec83b776945690826833ca 100644 (file)
@@ -118,14 +118,16 @@ void display_main_menu(void)
        wprintf("</td></tr>"
                "<tr valign=top><td width=50%%>");
 
-       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("</td><td width=50%%>");
 
diff --git a/webcit/openid.c b/webcit/openid.c
new file mode 100644 (file)
index 0000000..b94f0fb
--- /dev/null
@@ -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("<div class=\"fix_scrollbar_bug\">");
+
+       svput("BOXTITLE", WCS_STRING, _("Manage Account/OpenID Associations"));
+       do_template("beginbox");
+
+       wprintf("FIXME -- we have to list the existing ones here");
+
+       wprintf("<hr>\n");
+
+        wprintf("<form method=\"POST\" action=\"openid_attach\">\n");
+       wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
+       wprintf(_("Add an OpenID: "));
+        wprintf("<input type=\"text\" name=\"openid_url\" class=\"openid_urlarea\" size=\"40\">\n");
+        wprintf("<input type=\"submit\" name=\"attach_button\" value=\"%s\">"
+               "</form></center>\n", _("Attach"));
+       do_template("endbox");
+       wprintf("</div>");
+       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();
+}
+
+
index 77f9e99413c4aa02b9508a5d02e22755f81bba94..54ffe46b59aab31231c4caa79fccd8b08175b180 100644 (file)
@@ -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. */
index 5f2551484fce433e2bff8bc196fbba61dfc5da53..cacacc181180ad2e9054281a52a2dbd7d2e2d679 100644 (file)
@@ -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);