Re-enable OpenID development code
[citadel.git] / webcit / openid.c
1 /*
2  * $Id$
3  */
4
5 #include "webcit.h"
6 #include "webserver.h"
7
8 /*
9  * Display the OpenIDs associated with an account
10  */
11 void display_openids(void)
12 {
13         char buf[1024];
14         int bg = 0;
15
16         output_headers(1, 1, 1, 0, 0, 0);
17
18         wprintf("<div class=\"fix_scrollbar_bug\">");
19
20         svput("BOXTITLE", WCS_STRING, _("Manage Account/OpenID Associations"));
21         do_template("beginbox");
22
23         wprintf("<table class=\"altern\">");
24
25         serv_puts("OIDL");
26         serv_getln(buf, sizeof buf);
27         if (buf[0] == '1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
28                 bg = 1 - bg;
29                 wprintf("<tr class=\"%s\">", (bg ? "even" : "odd"));
30                 wprintf("<td><img src=\"static/openid-small.gif\"></td><td>");
31                 escputs(buf);
32                 wprintf("</td><td>%s</td></tr>\n", _("(delete)") );     // FIXME implement delete
33         }
34
35         wprintf("</table><br />\n");
36
37         wprintf("<form method=\"POST\" action=\"openid_attach\">\n");
38         wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
39         wprintf(_("Add an OpenID: "));
40         wprintf("<input type=\"text\" name=\"openid_url\" class=\"openid_urlarea\" size=\"40\">\n");
41         wprintf("<input type=\"submit\" name=\"attach_button\" value=\"%s\">"
42                 "</form></center>\n", _("Attach"));
43         do_template("endbox");
44         wprintf("</div>");
45         wDumpContent(2);
46 }
47
48
49 /*
50  * Attempt to attach an OpenID to an existing, logged-in account
51  */
52 void openid_attach(void) {
53         char buf[4096];
54
55         if (havebstr("attach_button")) {
56                 lprintf(CTDL_DEBUG, "Attempting to attach %s\n", bstr("openid_url"));
57
58                 snprintf(buf, sizeof buf,
59                         "OIDS %s|%s://%s/finalize_openid_login|%s://%s",
60                         bstr("openid_url"),
61                         (is_https ? "https" : "http"), WC->http_host,
62                         (is_https ? "https" : "http"), WC->http_host
63                 );
64
65                 serv_puts(buf);
66                 serv_getln(buf, sizeof buf);
67                 if (buf[0] == '2') {
68                         lprintf(CTDL_DEBUG, "OpenID server contacted; redirecting to %s\n", &buf[4]);
69                         http_redirect(&buf[4]);
70                         return;
71                 }
72         }
73
74         /* If we get to this point then something failed. */
75         display_openids();
76 }
77
78