Revert "Removed the "fix_scrollbarbug" div and all references to it."
[citadel.git] / webcit / openid.c
index 519100d921eed41a4cf397c43f1e6efdd28eee70..8842e88102549f3f214d7d480a58a05a2417c917 100644 (file)
@@ -1,6 +1,3 @@
-/*
- * $Id$
- */
 
 #include "webcit.h"
 #include "webserver.h"
  */
 void display_openids(void)
 {
+       wcsession *WCC = WC;
        char buf[1024];
        int bg = 0;
 
        output_headers(1, 1, 1, 0, 0, 0);
 
-       wprintf("<div class=\"fix_scrollbar_bug\">");
+       wc_printf("<div class=\"fix_scrollbar_bug\">");
 
-       svput("BOXTITLE", WCS_STRING, _("Manage Account/OpenID Associations"));
-       do_template("beginbox");
+       do_template("beginbox_1", NULL);
+       StrBufAppendBufPlain(WCC->WBuf, _("Manage Account/OpenID Associations"), -1, 0);
+       do_template("beginbox_2", NULL);
 
-       wprintf("<table class=\"altern\">");
+       if (WCC->serv_info->serv_supports_openid) {
 
-       serv_puts("OIDL");
-       serv_getln(buf, sizeof buf);
-       if (buf[0] == '1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
-               bg = 1 - bg;
-               wprintf("<tr class=\"%s\">", (bg ? "even" : "odd"));
-               wprintf("<td><img src=\"static/openid-small.gif\"></td><td>");
-               escputs(buf);
-               wprintf("</td><td>%s</td></tr>\n", _("(delete)") );     // FIXME implement delete
+               wc_printf("<table class=\"altern\">");
+       
+               serv_puts("OIDL");
+               serv_getln(buf, sizeof buf);
+               if (buf[0] == '1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
+                       bg = 1 - bg;
+                       wc_printf("<tr class=\"%s\">", (bg ? "even" : "odd"));
+                       wc_printf("<td><img src=\"static/openid-small.gif\"></td><td>");
+                       escputs(buf);
+                       wc_printf("</td><td>");
+                       wc_printf("<a href=\"openid_detach?id_to_detach=");
+                       urlescputs(buf);
+                       wc_printf("\" onClick=\"return confirm('%s');\">",
+                               _("Do you really want to delete this OpenID?"));
+                       wc_printf("%s</a>", _("(delete)"));
+                       wc_printf("</td></tr>\n");
+               }
+       
+               wc_printf("</table><br />\n");
+       
+               wc_printf("<form method=\"POST\" action=\"openid_attach\">\n");
+               wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WCC->nonce);
+               wc_printf(_("Add an OpenID: "));
+               wc_printf("<input type=\"text\" name=\"openid_url\" class=\"openid_urlarea\" size=\"40\">\n");
+               wc_printf("<input type=\"submit\" name=\"attach_button\" value=\"%s\">"
+                       "</form></center>\n", _("Attach"));
        }
 
-       wprintf("</table><br />\n");
+       else {
+               wc_printf(_("%s does not permit authentication via OpenID."), ChrPtr(WCC->serv_info->serv_humannode));
+       }
 
-        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>");
+       do_template("endbox", NULL);
+       wc_printf("</div>");
        wDumpContent(2);
 }
 
@@ -53,13 +66,14 @@ 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",
+                       "OIDS %s|%s/finalize_openid_login|%s",
                        bstr("openid_url"),
-                       (is_https ? "https" : "http"), WC->http_host,
-                       (is_https ? "https" : "http"), WC->http_host
+                       ChrPtr(site_prefix),
+                       ChrPtr(site_prefix)
                );
 
                serv_puts(buf);
@@ -69,6 +83,9 @@ void openid_attach(void) {
                        http_redirect(&buf[4]);
                        return;
                }
+               else {
+                       lprintf(CTDL_DEBUG, "OpenID attach failed: %s\n", &buf[4]);
+               }
        }
 
        /* If we get to this point then something failed. */
@@ -76,3 +93,28 @@ void openid_attach(void) {
 }
 
 
+/*
+ * Detach an OpenID from the currently logged-in account
+ */
+void openid_detach(void) {
+       char buf[1024];
+
+       if (havebstr("id_to_detach")) {
+               serv_printf("OIDD %s", bstr("id_to_detach"));
+               serv_getln(buf, sizeof buf);
+               if (buf[0] != '2') {
+                       strcpy(WC->ImportantMessage, &buf[4]);
+               }
+       }
+
+       display_openids();
+}
+
+void 
+InitModule_OPENID
+(void)
+{
+       WebcitAddUrlHandler(HKEY("display_openids"), "", 0, display_openids, 0);
+       WebcitAddUrlHandler(HKEY("openid_attach"), "", 0, openid_attach, 0);
+       WebcitAddUrlHandler(HKEY("openid_detach"), "", 0, openid_detach, 0);
+}