]> code.citadel.org Git - citadel.git/blobdiff - webcit/auth.c
Success! We can now log in an existing user with OpenID.
[citadel.git] / webcit / auth.c
index 023c54e55d26fdec02e8475512addd00cce8f440..96503c1a7f33c5608694336a567d06b8dc5bb701 100644 (file)
@@ -78,7 +78,7 @@ void display_login(char *mesg)
                svput("NEWUSER_BUTTON_POST", WCS_STRING, "");
        }
 
-#ifdef TECH_PREVIEW
+       if (1) {        // FIXME we have to check whether the server offers openid
                svprintf(HKEY("OFFER_OPENID_LOGIN"), WCS_STRING,
                        "<div align=center>"
                        "<a href=\"display_openid_login\">"
@@ -88,9 +88,10 @@ void display_login(char *mesg)
                        ,
                        "Log in using OpenID"
                );
-#else
+       }
+       else {
                svput("OFFER_OPENID_LOGIN", WCS_STRING, "");
-#endif
+       }
 
        do_template("login");
 
@@ -249,6 +250,8 @@ void do_login(void)
        if (WC->logged_in) {
                if (WC->need_regi) {
                        display_reg(1);
+               } else if (WC->need_vali) {
+                       validate();
                } else {
                        do_welcome();
                }
@@ -308,34 +311,76 @@ void do_openid_login(void)
 void finalize_openid_login(void)
 {
        char buf[1024];
+       struct wcsession *WCC = WC;
+       int already_logged_in = (WCC->logged_in) ;
+       int linecount = 0;
+       char result[128] = "";
+       char username[128] = "";
+       char password[128] = "";
 
        if (havebstr("openid.mode")) {
                if (!strcasecmp(bstr("openid.mode"), "id_res")) {
 
-// openid.mode = [6]  id_res
-// openid.identity = [50]  http://uncensored.citadel.org/~ajc/MyID.config.php
-// openid.assoc_handle = [26]  6ekac3ju181tgepk7v4h9r7ui7
-// openid.return_to = [42]  http://jemcaterers.net/finish_openid_login
-// openid.sreg.nickname = [17]  IGnatius T Foobar
-// openid.sreg.email = [26]  ajc@uncensored.citadel.org
-// openid.sreg.fullname = [10]  Art Cancro
-// openid.sreg.postcode = [5]  10549
-// openid.sreg.country = [2]  US
-// openid.signed = [102]  mode,identity,assoc_handle,return_to,sreg.nickname,sreg.email,sreg.fullname,sreg.postcode,sreg.country
-// openid.sig = [28]  vixxxU4MAqWfxxxxCfrHv3TxxxhEw=
-
                        // FIXME id accepted but the code isn't finished
-                       serv_printf("OIDF %s|%s",
-                               bstr("openid.assoc_handle"),
-                               bstr("openid.invalidate_handle")
-                       );
+                       serv_puts("OIDF");
                        serv_getln(buf, sizeof buf);
-                       display_openid_login(buf);
-                       return;
 
+                       if (buf[0] == '8') {
+                               urlcontent *u;
+                               void *U;
+                               long HKLen;
+                               char *HKey;
+                               HashPos *Cursor;
+                               
+                               Cursor = GetNewHashPos ();
+                               while (GetNextHashPos(WCC->urlstrings, Cursor, &HKLen, &HKey, &U)) {
+                                       u = (urlcontent*) U;
+                                       if (!strncasecmp(u->url_key, "openid.", 7)) {
+                                               serv_printf("%s|%s", &u->url_key[7], u->url_data);
+                                       }
+                               }
+
+                               serv_puts("000");
+
+                               linecount = 0;
+                               while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
+                                       if (linecount == 0) safestrncpy(result, buf, sizeof result);
+                                       if (!strcasecmp(result, "authenticate")) {
+                                               if (linecount == 1) {
+                                                       safestrncpy(username, buf, sizeof username);
+                                               }
+                                               else if (linecount == 2) {
+                                                       safestrncpy(password, buf, sizeof password);
+                                               }
+                                       }
+                                       ++linecount;
+                               }
+                       }
+               }
+       }
+
+       /* If we were already logged in, this was an attempt to associate an OpenID account */
+       if (already_logged_in) {
+               display_openids();
+               return;
+       }
+
+       /* Was the claimed ID associated with an existing account?  Then log in that account now. */
+       if (!strcasecmp(result, "authenticate")) {
+               serv_printf("USER %s", username);
+               serv_getln(buf, sizeof buf);
+               if (buf[0] == '3') {
+                       serv_printf("PASS %s", password);
+                       serv_getln(buf, sizeof buf);
+                       if (buf[0] == '2') {
+                               become_logged_in(username, password, buf);
+                       }
                }
        }
 
+       /* FIXME -- right here we have to put the code to log in a new user */
+
+       /* Did we manage to log in?  If so, continue with the normal flow... */
        if (WC->logged_in) {
                if (WC->need_regi) {
                        display_reg(1);
@@ -349,16 +394,10 @@ void finalize_openid_login(void)
 }
 
 
-
-
-
-
-
-
 /*
- * display the user a welcome screen.
+ * Display a welcome screen to the user.
  *
- * if this is the first time login, and the web based setup is enabled, 
+ * If this is the first time login, and the web based setup is enabled, 
  * lead the user through the setup routines
  */
 void do_welcome(void)