* add a Display name to our handlers; this will be used by DAV handlers.
[citadel.git] / webcit / openid.c
index e34425832036b55850cdac5c699bf412ded8e323..e3881924fbd7a0ae7c73a250279e6c438d01640f 100644 (file)
@@ -10,6 +10,7 @@
  */
 void display_openids(void)
 {
+       wcsession *WCC = WC;
        char buf[1024];
        int bg = 0;
 
@@ -18,35 +19,43 @@ void display_openids(void)
        wprintf("<div class=\"fix_scrollbar_bug\">");
 
        svput("BOXTITLE", WCS_STRING, _("Manage Account/OpenID Associations"));
-       do_template("beginbox");
-
-       wprintf("<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;
-               wprintf("<tr class=\"%s\">", (bg ? "even" : "odd"));
-               wprintf("<td><img src=\"static/openid-small.gif\"></td><td>");
-               escputs(buf);
-               wprintf("</td><td>");
-               wprintf("<a href=\"openid_detach?id_to_detach=");
-               urlescputs(buf);
-               wprintf("\" onClick=\"return confirm('%s');\">",
-                       _("Do you really want to delete this OpenID?"));
-               wprintf("%s</a>", _("(delete)"));
-               wprintf("</td></tr>\n");
+       do_template("beginboxx", NULL);
+
+       if (WCC->serv_info->serv_supports_openid) {
+
+               wprintf("<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;
+                       wprintf("<tr class=\"%s\">", (bg ? "even" : "odd"));
+                       wprintf("<td><img src=\"static/openid-small.gif\"></td><td>");
+                       escputs(buf);
+                       wprintf("</td><td>");
+                       wprintf("<a href=\"openid_detach?id_to_detach=");
+                       urlescputs(buf);
+                       wprintf("\" onClick=\"return confirm('%s');\">",
+                               _("Do you really want to delete this OpenID?"));
+                       wprintf("%s</a>", _("(delete)"));
+                       wprintf("</td></tr>\n");
+               }
+       
+               wprintf("</table><br />\n");
+       
+               wprintf("<form method=\"POST\" action=\"openid_attach\">\n");
+               wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WCC->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"));
        }
 
-       wprintf("</table><br />\n");
+       else {
+               wprintf(_("%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");
+       do_template("endbox", NULL);
        wprintf("</div>");
        wDumpContent(2);
 }
@@ -59,13 +68,15 @@ void openid_attach(void) {
        char buf[4096];
 
        if (havebstr("attach_button")) {
+               wcsession *WCC = WC;
+
                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
+                        "OIDS %s|%s://%s/finalize_openid_login|%s://%s",
+                        bstr("openid_url"),
+                        (is_https ? "https" : "http"), ChrPtr(WCC->Hdr->HR.http_host),
+                        (is_https ? "https" : "http"), ChrPtr(WCC->Hdr->HR.http_host)
                );
 
                serv_puts(buf);
@@ -75,6 +86,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. */
@@ -98,3 +112,12 @@ void openid_detach(void) {
 
        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);
+}