Removed the "fix_scrollbarbug" div and all references to it.
[citadel.git] / webcit / openid.c
1
2 #include "webcit.h"
3 #include "webserver.h"
4
5 /*
6  * Display the OpenIDs associated with an account
7  */
8 void display_openids(void)
9 {
10         wcsession *WCC = WC;
11         char buf[1024];
12         int bg = 0;
13
14         output_headers(1, 1, 1, 0, 0, 0);
15
16         do_template("beginbox_1", NULL);
17         StrBufAppendBufPlain(WCC->WBuf, _("Manage Account/OpenID Associations"), -1, 0);
18         do_template("beginbox_2", NULL);
19
20         if (WCC->serv_info->serv_supports_openid) {
21
22                 wc_printf("<table class=\"altern\">");
23         
24                 serv_puts("OIDL");
25                 serv_getln(buf, sizeof buf);
26                 if (buf[0] == '1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
27                         bg = 1 - bg;
28                         wc_printf("<tr class=\"%s\">", (bg ? "even" : "odd"));
29                         wc_printf("<td><img src=\"static/openid-small.gif\"></td><td>");
30                         escputs(buf);
31                         wc_printf("</td><td>");
32                         wc_printf("<a href=\"openid_detach?id_to_detach=");
33                         urlescputs(buf);
34                         wc_printf("\" onClick=\"return confirm('%s');\">",
35                                 _("Do you really want to delete this OpenID?"));
36                         wc_printf("%s</a>", _("(delete)"));
37                         wc_printf("</td></tr>\n");
38                 }
39         
40                 wc_printf("</table><br />\n");
41         
42                 wc_printf("<form method=\"POST\" action=\"openid_attach\">\n");
43                 wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WCC->nonce);
44                 wc_printf(_("Add an OpenID: "));
45                 wc_printf("<input type=\"text\" name=\"openid_url\" class=\"openid_urlarea\" size=\"40\">\n");
46                 wc_printf("<input type=\"submit\" name=\"attach_button\" value=\"%s\">"
47                         "</form></center>\n", _("Attach"));
48         }
49
50         else {
51                 wc_printf(_("%s does not permit authentication via OpenID."), ChrPtr(WCC->serv_info->serv_humannode));
52         }
53
54         do_template("endbox", NULL);
55         wDumpContent(2);
56 }
57
58
59 /*
60  * Attempt to attach an OpenID to an existing, logged-in account
61  */
62 void openid_attach(void) {
63         char buf[4096];
64
65         if (havebstr("attach_button")) {
66
67                 lprintf(CTDL_DEBUG, "Attempting to attach %s\n", bstr("openid_url"));
68
69                 snprintf(buf, sizeof buf,
70                         "OIDS %s|%s/finalize_openid_login|%s",
71                         bstr("openid_url"),
72                         ChrPtr(site_prefix),
73                         ChrPtr(site_prefix)
74                 );
75
76                 serv_puts(buf);
77                 serv_getln(buf, sizeof buf);
78                 if (buf[0] == '2') {
79                         lprintf(CTDL_DEBUG, "OpenID server contacted; redirecting to %s\n", &buf[4]);
80                         http_redirect(&buf[4]);
81                         return;
82                 }
83                 else {
84                         lprintf(CTDL_DEBUG, "OpenID attach failed: %s\n", &buf[4]);
85                 }
86         }
87
88         /* If we get to this point then something failed. */
89         display_openids();
90 }
91
92
93 /*
94  * Detach an OpenID from the currently logged-in account
95  */
96 void openid_detach(void) {
97         char buf[1024];
98
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]);
104                 }
105         }
106
107         display_openids();
108 }
109
110 void 
111 InitModule_OPENID
112 (void)
113 {
114         WebcitAddUrlHandler(HKEY("display_openids"), "", 0, display_openids, 0);
115         WebcitAddUrlHandler(HKEY("openid_attach"), "", 0, openid_attach, 0);
116         WebcitAddUrlHandler(HKEY("openid_detach"), "", 0, openid_detach, 0);
117 }