* When saving a Task, if the status is COMPLETED then also set PERCENT-COMPLETE:100...
[citadel.git] / webcit / openid.c
blobdc6d09838f20ae8ddc3383e2034e96dc1548e044
1 /*
2 * $Id$
3 */
5 #include "webcit.h"
6 #include "webserver.h"
8 /*
9 * Display the OpenIDs associated with an account
11 void display_openids(void)
13 char buf[1024];
14 int bg = 0;
16 output_headers(1, 1, 1, 0, 0, 0);
18 wprintf("<div class=\"fix_scrollbar_bug\">");
20 svput("BOXTITLE", WCS_STRING, _("Manage Account/OpenID Associations"));
21 do_template("beginboxx", NULL);
23 if (serv_info.serv_supports_openid) {
25 wprintf("<table class=\"altern\">");
27 serv_puts("OIDL");
28 serv_getln(buf, sizeof buf);
29 if (buf[0] == '1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
30 bg = 1 - bg;
31 wprintf("<tr class=\"%s\">", (bg ? "even" : "odd"));
32 wprintf("<td><img src=\"static/openid-small.gif\"></td><td>");
33 escputs(buf);
34 wprintf("</td><td>");
35 wprintf("<a href=\"openid_detach?id_to_detach=");
36 urlescputs(buf);
37 wprintf("\" onClick=\"return confirm('%s');\">",
38 _("Do you really want to delete this OpenID?"));
39 wprintf("%s</a>", _("(delete)"));
40 wprintf("</td></tr>\n");
43 wprintf("</table><br />\n");
45 wprintf("<form method=\"POST\" action=\"openid_attach\">\n");
46 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
47 wprintf(_("Add an OpenID: "));
48 wprintf("<input type=\"text\" name=\"openid_url\" class=\"openid_urlarea\" size=\"40\">\n");
49 wprintf("<input type=\"submit\" name=\"attach_button\" value=\"%s\">"
50 "</form></center>\n", _("Attach"));
53 else {
54 wprintf(_("%s does not permit authentication via OpenID."), ChrPtr(serv_info.serv_humannode));
57 do_template("endbox", NULL);
58 wprintf("</div>");
59 wDumpContent(2);
64 * Attempt to attach an OpenID to an existing, logged-in account
66 void openid_attach(void) {
67 char buf[4096];
69 if (havebstr("attach_button")) {
70 lprintf(CTDL_DEBUG, "Attempting to attach %s\n", bstr("openid_url"));
72 snprintf(buf, sizeof buf,
73 "OIDS %s|%s://%s/finalize_openid_login|%s://%s",
74 bstr("openid_url"),
75 (is_https ? "https" : "http"), WC->http_host,
76 (is_https ? "https" : "http"), WC->http_host
79 serv_puts(buf);
80 serv_getln(buf, sizeof buf);
81 if (buf[0] == '2') {
82 lprintf(CTDL_DEBUG, "OpenID server contacted; redirecting to %s\n", &buf[4]);
83 http_redirect(&buf[4]);
84 return;
88 /* If we get to this point then something failed. */
89 display_openids();
94 * Detach an OpenID from the currently logged-in account
96 void openid_detach(void) {
97 char buf[1024];
99 if (havebstr("id_to_detach")) {
100 serv_printf("OIDD %s", bstr("id_to_detach"));
101 serv_getln(buf, sizeof buf);
102 if (buf[0] != '2') {
103 strcpy(WC->ImportantMessage, &buf[4]);
107 display_openids();
110 void
111 InitModule_OPENID
112 (void)
114 WebcitAddUrlHandler(HKEY("display_openids"), display_openids, 0);
115 WebcitAddUrlHandler(HKEY("openid_attach"), openid_attach, 0);
116 WebcitAddUrlHandler(HKEY("openid_detach"), openid_detach, 0);