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