]> code.citadel.org Git - citadel.git/blobdiff - webcit/auth.c
OpenID manual create is now functionally complete.
[citadel.git] / webcit / auth.c
index be62db44777c56cb0f22d7e84c293e7ccdc50b36..905cd8722aada3c464410efb07a3a45520088015 100644 (file)
@@ -24,8 +24,6 @@
 
 extern uint32_t hashlittle( const void *key, size_t length, uint32_t initval);
 
-void display_reg(int during_login);
-
 /*
  * Access level definitions.  This is initialized from a function rather than a
  * static array so that the strings may be localized.
@@ -167,21 +165,21 @@ void ajax_login_username_password(void) {
  * modal/ajax version of 'new user' (username and password)
  */
 void ajax_login_newuser(void) {
-       StrBuf *Buf = NewStrBuf();
+       StrBuf *NBuf = NewStrBuf();
+       StrBuf *SBuf = NewStrBuf();
 
        serv_printf("NEWU %s", bstr("name"));
-       StrBuf_ServGetln(Buf);
-       if (GetServerStatus(Buf, NULL) == 2) {
+       StrBuf_ServGetln(NBuf);
+       if (GetServerStatus(NBuf, NULL) == 2) {
+               become_logged_in(sbstr("name"), sbstr("pass"), NBuf);
                serv_printf("SETP %s", bstr("pass"));
-               StrBuf_ServGetln(Buf);
-               if (GetServerStatus(Buf, NULL) == 2) {
-                       become_logged_in(sbstr("name"), sbstr("pass"), Buf);
-               }
+               StrBuf_ServGetln(SBuf);
        }
 
        /* The client is expecting to read back a citadel protocol response */
-       wc_printf("%s", ChrPtr(Buf));
-       FreeStrBuf(&Buf);
+       wc_printf("%s", ChrPtr(NBuf));
+       FreeStrBuf(&NBuf);
+       FreeStrBuf(&SBuf);
 }
 
 
@@ -193,45 +191,54 @@ void openid_manual_create(void)
 {
        StrBuf *Buf;
 
+       /* Did the user change his mind?  Pack up and go home. */
        if (havebstr("exit_action")) {
-               do_logout();
+               begin_burst();
+               output_headers(1, 0, 0, 0, 1, 0);
+               do_template("authpopup_finished", NULL);
+               end_burst();
                return;
        }
 
-       if (havebstr("newuser_action")) {
-               Buf = NewStrBuf();
-               serv_printf("OIDC %s", bstr("name"));
-               StrBuf_ServGetln(Buf);
-               if (GetServerStatus(Buf, NULL) == 2) {
-                       StrBuf *gpass;
-
-                       gpass = NewStrBuf();
-                       serv_puts("SETP GENERATE_RANDOM_PASSWORD");
-                       StrBuf_ServGetln(gpass);
-                       StrBufCutLeft(gpass, 4);
-                       become_logged_in(sbstr("name"), gpass, Buf);
-                       FreeStrBuf(&gpass);
-               }
-               FreeStrBuf(&Buf);
+
+       /* Ok, let's give this a try.  Can we create the new user? */
+
+       Buf = NewStrBuf();
+       serv_printf("OIDC %s", bstr("name"));
+       StrBuf_ServGetln(Buf);
+       if (GetServerStatus(Buf, NULL) == 2) {
+               StrBuf *gpass;
+
+               gpass = NewStrBuf();
+               serv_puts("SETP GENERATE_RANDOM_PASSWORD");
+               StrBuf_ServGetln(gpass);
+               StrBufCutLeft(gpass, 4);
+               become_logged_in(sbstr("name"), gpass, Buf);
+               FreeStrBuf(&gpass);
        }
+       FreeStrBuf(&Buf);
 
+       /* Did we manage to log in?  If so, continue with the normal flow... */
        if (WC->logged_in) {
-               if (WC->need_regi) {
-                       display_reg(1);
-               } else if (WC->need_vali) {
-                       validate();
-               } else {
-                       do_welcome();
+               if (WC->logged_in) {
+                       begin_burst();
+                       output_headers(1, 0, 0, 0, 1, 0);
+                       do_template("authpopup_finished", NULL);
+                       end_burst();
                }
        } else {
-               const StrBuf *Buf;
 
+               /* Still no good!  Go back to teh dialog to select a username */
+               const StrBuf *Buf;
                putbstr("__claimed_id", NewStrBufDup(sbstr("openid_url")));
                Buf = sbstr("name");
                if (StrLength(Buf) > 0)
                        putbstr("__username", NewStrBufDup(Buf));
                begin_burst();
+               output_headers(1, 0, 0, 0, 1, 0);
+               wc_printf("<html><body>");
                do_template("openid_manual_create", NULL);
+               wc_printf("</body></html>");
                end_burst();
        }
 
@@ -278,7 +285,6 @@ void finalize_openid_login(void)
 {
        StrBuf *Buf;
        wcsession *WCC = WC;
-       int already_logged_in = (WCC->logged_in) ;
        int linecount = 0;
        StrBuf *result = NULL;
        StrBuf *username = NULL;
@@ -338,33 +344,38 @@ void finalize_openid_login(void)
                }
        }
 
-       /* If we were already logged in, this was an attempt to associate an OpenID account 
-       FIXME put this back in
-       if (already_logged_in) {
+       /*
+        * Is this an attempt to associate a new OpenID with an account that is already logged in?
+        */
+       if ( (WCC->logged_in) && (havebstr("attach_existing")) ) {
                display_openids();
-               FreeStrBuf(&result);
-               FreeStrBuf(&username);
-               FreeStrBuf(&password);
-               FreeStrBuf(&claimed_id);
-               FreeStrBuf(&logged_in_response);
-               return;
        }
-       */
 
        /* If this operation logged us in, either by connecting with an existing account or by
         * auto-creating one using Simple Registration Extension, we're already on our way.
         */
-       if (!strcasecmp(ChrPtr(result), "authenticate")) {
+       else if (!strcasecmp(ChrPtr(result), "authenticate")) {
                become_logged_in(username, password, logged_in_response);
+
+               /* Did we manage to log in?  If so, continue with the normal flow... */
+               if (WC->logged_in) {
+                       begin_burst();
+                       output_headers(1, 0, 0, 0, 1, 0);
+                       do_template("authpopup_finished", NULL);
+                       end_burst();
+               } else {
+                       begin_burst();
+                       output_headers(1, 0, 0, 0, 1, 0);
+                       wc_printf("<html><body>");
+                       wc_printf(_("An error has occurred."));
+                       wc_printf("</body></html>");
+                       end_burst();
+               }
        }
 
-       /* The specified OpenID was verified but the desired user name was either not specified via SRI
+       /* The specified OpenID was verified but the desired user name was either not specified via SRE
         * or conflicts with an existing user.  Either way the user will need to specify a new name.
         */
-
-/*
- * FIXME make this work again!!!!
- *
        else if (!strcasecmp(ChrPtr(result), "verify_only")) {
                putbstr("__claimed_id", claimed_id);
                claimed_id = NULL;
@@ -373,24 +384,20 @@ void finalize_openid_login(void)
                        username = NULL;
                }
                begin_burst();
+               output_headers(1, 0, 0, 0, 1, 0);
+               wc_printf("<html><body>");
                do_template("openid_manual_create", NULL);
+               wc_printf("</body></html>");
                end_burst();
        }
-*/
-
 
-
-       /* Did we manage to log in?  If so, continue with the normal flow... */
-       if (WC->logged_in) {
-               begin_burst();
-               output_headers(1, 0, 0, 0, 1, 0);
-               do_template("authpopup_finished", NULL);
-               end_burst();
-       } else {
+       /* Something went VERY wrong if we get to this point */
+       else {
+               syslog(1, "finalize_openid_login() failed to do anything.  This is a code problem.\n");
                begin_burst();
                output_headers(1, 0, 0, 0, 1, 0);
                wc_printf("<html><body>");
-               wc_printf(_("An error has occurred."));         /* FIXME do something prettier here */
+               wc_printf(_("An error has occurred."));
                wc_printf("</body></html>");
                end_burst();
        }
@@ -730,7 +737,6 @@ void display_reg(int during_login)
                FreeStrBuf(&ReturnTo);
        }
 
-       /* FIXME - don't we have to free VCMsg and VCAtt ?? */
 }