]> code.citadel.org Git - citadel.git/blobdiff - webcit/openid.c
* add new 'Context' Parameter to the template call
[citadel.git] / webcit / openid.c
index 519100d921eed41a4cf397c43f1e6efdd28eee70..2d905bd50d915d7abd7a1c17227d41241e584373 100644 (file)
@@ -18,29 +18,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>%s</td></tr>\n", _("(delete)") );     // FIXME implement delete
+       do_template("beginbox", NULL);
+
+       if (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", 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"));
        }
 
-       wprintf("</table><br />\n");
+       else {
+               wprintf(_("%s does not permit authentication via OpenID."), 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);
 }
@@ -76,3 +90,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"), display_openids, 0);
+       WebcitAddUrlHandler(HKEY("openid_attach"), openid_attach, 0);
+       WebcitAddUrlHandler(HKEY("openid_detach"), openid_detach, 0);
+}