X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=webcit%2Fopenid.c;h=ca71d6793c51ab72ebae517599022a92d599e618;hb=HEAD;hp=e34425832036b55850cdac5c699bf412ded8e323;hpb=4eacc474af13ee15b4bd82c3d7bff427b89c2618;p=citadel.git diff --git a/webcit/openid.c b/webcit/openid.c index e34425832..b56c01c24 100644 --- a/webcit/openid.c +++ b/webcit/openid.c @@ -1,53 +1,68 @@ /* - * $Id$ + * Copyright (c) 1996-2012 by the citadel.org team + * + * This program is open source software. You can redistribute it and/or + * modify it under the terms of the GNU General Public License, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. */ #include "webcit.h" -#include "webserver.h" + /* * Display the OpenIDs associated with an account */ void display_openids(void) { + wcsession *WCC = WC; char buf[1024]; int bg = 0; output_headers(1, 1, 1, 0, 0, 0); - wprintf("
"); - - svput("BOXTITLE", WCS_STRING, _("Manage Account/OpenID Associations")); - do_template("beginbox"); - - wprintf(""); - - serv_puts("OIDL"); - serv_getln(buf, sizeof buf); - if (buf[0] == '1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { - bg = 1 - bg; - wprintf("", (bg ? "even" : "odd")); - wprintf("\n"); + do_template("box_begin_1"); + StrBufAppendBufPlain(WCC->WBuf, _("Manage Account/OpenID Associations"), -1, 0); + do_template("box_begin_2"); + + if (WCC->serv_info->serv_supports_openid) { + + wc_printf("
"); - escputs(buf); - wprintf(""); - wprintf("", - _("Do you really want to delete this OpenID?")); - wprintf("%s", _("(delete)")); - wprintf("
"); + + serv_puts("OIDL"); + serv_getln(buf, sizeof buf); + if (buf[0] == '1') while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { + bg = 1 - bg; + wc_printf("", (bg ? "even" : "odd")); + wc_printf("\n"); + } + + wc_printf("
"); + escputs(buf); + wc_printf(""); + wc_printf("", + _("Do you really want to delete this OpenID?")); + wc_printf("%s", _("(delete)")); + wc_printf("

\n"); + + wc_printf("
\n"); + wc_printf("\n", WCC->nonce); + wc_printf(_("Add an OpenID: ")); + wc_printf("\n"); + wc_printf("" + "
\n", _("Attach")); } - wprintf("
\n"); + else { + wc_printf(_("%s does not permit authentication via OpenID."), ChrPtr(WCC->serv_info->serv_humannode)); + } - wprintf("
\n"); - wprintf("\n", WC->nonce); - wprintf(_("Add an OpenID: ")); - wprintf("\n"); - wprintf("" - "
\n", _("Attach")); - do_template("endbox"); - wprintf("
"); + do_template("box_end"); wDumpContent(2); } @@ -59,22 +74,26 @@ void openid_attach(void) { char buf[4096]; if (havebstr("attach_button")) { - lprintf(CTDL_DEBUG, "Attempting to attach %s\n", bstr("openid_url")); + + syslog(LOG_DEBUG, "Attempting to attach %s\n", bstr("openid_url")); snprintf(buf, sizeof buf, - "OIDS %s|%s://%s/finalize_openid_login|%s://%s", + "OIDS %s|%s/finalize_openid_login?attach_existing=1|%s", bstr("openid_url"), - (is_https ? "https" : "http"), WC->http_host, - (is_https ? "https" : "http"), WC->http_host + ChrPtr(site_prefix), + ChrPtr(site_prefix) ); serv_puts(buf); serv_getln(buf, sizeof buf); if (buf[0] == '2') { - lprintf(CTDL_DEBUG, "OpenID server contacted; redirecting to %s\n", &buf[4]); + syslog(LOG_DEBUG, "OpenID server contacted; redirecting to %s\n", &buf[4]); http_redirect(&buf[4]); return; } + else { + syslog(LOG_DEBUG, "OpenID attach failed: %s\n", &buf[4]); + } } /* If we get to this point then something failed. */ @@ -86,15 +105,24 @@ void openid_attach(void) { * Detach an OpenID from the currently logged-in account */ void openid_detach(void) { - char buf[1024]; + StrBuf *Line; if (havebstr("id_to_detach")) { serv_printf("OIDD %s", bstr("id_to_detach")); - serv_getln(buf, sizeof buf); - if (buf[0] != '2') { - strcpy(WC->ImportantMessage, &buf[4]); - } + Line = NewStrBuf(); + StrBuf_ServGetln(Line); + GetServerStatusMsg(Line, NULL, 1, 2); + FreeStrBuf(&Line); } display_openids(); } + +void +InitModule_OPENID +(void) +{ + WebcitAddUrlHandler(HKEY("display_openids"), "", 0, display_openids, 0); + WebcitAddUrlHandler(HKEY("openid_attach"), "", 0, openid_attach, 0); + WebcitAddUrlHandler(HKEY("openid_detach"), "", 0, openid_detach, 0); +}