Added some glue code for attachment of an OpenID to
[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         output_headers(1, 1, 1, 0, 0, 0);
14
15         wprintf("<div class=\"fix_scrollbar_bug\">");
16
17         svput("BOXTITLE", WCS_STRING, _("Manage Account/OpenID Associations"));
18         do_template("beginbox");
19
20         wprintf("FIXME -- we have to list the existing ones here");
21
22         wprintf("<hr>\n");
23
24         wprintf("<form method=\"POST\" action=\"openid_attach\">\n");
25         wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
26         wprintf(_("Add an OpenID: "));
27         wprintf("<input type=\"text\" name=\"openid_url\" class=\"openid_urlarea\" size=\"40\">\n");
28         wprintf("<input type=\"submit\" name=\"attach_button\" value=\"%s\">"
29                 "</form></center>\n", _("Attach"));
30         do_template("endbox");
31         wprintf("</div>");
32         wDumpContent(2);
33 }
34
35
36 /*
37  * Attempt to attach an OpenID to an existing, logged-in account
38  */
39 void openid_attach(void) {
40         char buf[4096];
41
42         if (havebstr("attach_button")) {
43                 lprintf(CTDL_DEBUG, "Attempting to attach %s\n", bstr("openid_url"));
44
45                 snprintf(buf, sizeof buf,
46                         "OIDS %s|%s://%s/finalize_openid_login|%s://%s",
47                         bstr("openid_url"),
48                         (is_https ? "https" : "http"), WC->http_host,
49                         (is_https ? "https" : "http"), WC->http_host
50                 );
51
52                 serv_puts(buf);
53                 serv_getln(buf, sizeof buf);
54                 if (buf[0] == '2') {
55                         lprintf(CTDL_DEBUG, "OpenID server contacted; redirecting to %s\n", &buf[4]);
56                         http_redirect(&buf[4]);
57                         return;
58                 }
59         }
60
61         /* If we get to this point then something failed. */
62         display_openids();
63 }
64
65