]> code.citadel.org Git - citadel.git/blobdiff - webcit/auth.c
Begin working on OpenID manual screen name selection mode
[citadel.git] / webcit / auth.c
index eba2e3bc4bce0f34089215bb8031df7881dfba2a..6c7c7bf6cb51b94d2b163169653c7ceb87b73eec 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.
@@ -140,97 +138,6 @@ void become_logged_in(const StrBuf *user, const StrBuf *pass, StrBuf *serv_respo
 }
 
 
-#ifdef __OLD__LOGIN__SCREEN__
-/* 
- * Perform authentication using a user name and password
- */
-void do_login(void)
-{
-       wcsession *WCC = WC;
-       StrBuf *Buf;
-       long ret, rc;
-
-       if (havebstr("language")) {
-               set_selected_language(bstr("language"));
-               go_selected_language();
-       }
-
-       if (havebstr("exit_action")) {
-               do_logout();
-               return;
-       }
-       Buf = NewStrBuf();
-       if (havebstr("login_action")) {
-               serv_printf("USER %s", bstr("name"));
-               StrBuf_ServGetln(Buf);
-               rc = GetServerStatus(Buf, &ret);
-               StrBufCutLeft(Buf, 4);
-               switch (rc) {
-               case 3:
-                       serv_printf("PASS %s", bstr("pass"));
-                       StrBuf_ServGetln(Buf);
-                       if (GetServerStatus(Buf, NULL) == 2) {
-                               become_logged_in(sbstr("name"), sbstr("pass"), Buf);
-                       } else {
-                               StrBufCutLeft(Buf, 4);
-                               AppendImportantMessage(SKEY(Buf));
-                               display_login();
-                               FreeStrBuf(&Buf);
-                               return;
-                       }
-                       break;
-               case 5:
-                       if (ret == 541)
-                       {
-                               AppendImportantMessage(SKEY(Buf));
-                               display_main_menu();
-                               return;
-                       }
-               default:
-                       AppendImportantMessage(SKEY(Buf));
-                       display_login();
-                       FreeStrBuf(&Buf);
-                       return;
-               }
-       }
-       if (havebstr("newuser_action")) {
-               if (!havebstr("pass")) {
-                       AppendImportantMessage(_("Blank passwords are not allowed."), -1);
-                       display_login();
-                       FreeStrBuf(&Buf);
-                       return;
-               }
-               serv_printf("NEWU %s", bstr("name"));
-               StrBuf_ServGetln(Buf);
-               if (GetServerStatus(Buf, NULL) == 2) {
-                       become_logged_in(sbstr("name"), sbstr("pass"), Buf);
-                       serv_printf("SETP %s", bstr("pass"));
-                       StrBuf_ServGetln(Buf); /* Don't care? */
-               } else {
-                       StrBufCutLeft(Buf, 4);
-                       AppendImportantMessage(SKEY(Buf));
-                       display_login();
-                       FreeStrBuf(&Buf);
-                       return;
-               }
-       }
-       if (WCC->logged_in) {
-               if (WCC->need_regi) {
-                       display_reg(1);
-               } else if (WCC->need_vali) {
-                       validate();
-               } else {
-                       do_welcome();
-               }
-       } else {
-               AppendImportantMessage(_("Your password was not accepted."), -1);
-               display_login();
-       }
-       FreeStrBuf(&Buf);
-}
-#endif
-
-
 /* 
  * modal/ajax version of 'login' (username and password)
  */
@@ -254,6 +161,29 @@ void ajax_login_username_password(void) {
 
 
 
+/* 
+ * modal/ajax version of 'new user' (username and password)
+ */
+void ajax_login_newuser(void) {
+       StrBuf *NBuf = NewStrBuf();
+       StrBuf *SBuf = NewStrBuf();
+
+       serv_printf("NEWU %s", bstr("name"));
+       StrBuf_ServGetln(NBuf);
+       if (GetServerStatus(NBuf, NULL) == 2) {
+               become_logged_in(sbstr("name"), sbstr("pass"), NBuf);
+               serv_printf("SETP %s", bstr("pass"));
+               StrBuf_ServGetln(SBuf);
+       }
+
+       /* The client is expecting to read back a citadel protocol response */
+       wc_printf("%s", ChrPtr(NBuf));
+       FreeStrBuf(&NBuf);
+       FreeStrBuf(&SBuf);
+}
+
+
+
 /* 
  * Try to create an account manually after an OpenID was verified
  */
@@ -346,7 +276,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;
@@ -406,9 +335,10 @@ 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);
@@ -417,7 +347,6 @@ void finalize_openid_login(void)
                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.
@@ -426,11 +355,9 @@ void finalize_openid_login(void)
                become_logged_in(username, password, logged_in_response);
        }
 
-       /* 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.
         */
-
-/*
        else if (!strcasecmp(ChrPtr(result), "verify_only")) {
                putbstr("__claimed_id", claimed_id);
                claimed_id = NULL;
@@ -439,12 +366,13 @@ void finalize_openid_login(void)
                        username = NULL;
                }
                begin_burst();
-               do_template("openid_manual_create", NULL);
+               output_headers(1, 0, 0, 0, 1, 0);
+               wc_printf("<html><body>");
+               wc_printf("FIXME -- manual create goes here -- FIXME");
+               /* 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) {
@@ -452,21 +380,11 @@ void finalize_openid_login(void)
                output_headers(1, 0, 0, 0, 1, 0);
                do_template("authpopup_finished", NULL);
                end_burst();
-
-               /* FIXME make all this crap work again
-               if (WC->need_regi) {
-                       display_reg(1);
-               } else {
-                       do_welcome();
-               }
-               */
-
        } else {
-               /* FIXME do something prettier here? */
                begin_burst();
                output_headers(1, 0, 0, 0, 1, 0);
                wc_printf("<html><body>");
-               wc_printf("error");
+               wc_printf(_("An error has occurred."));
                wc_printf("</body></html>");
                end_burst();
        }
@@ -771,7 +689,7 @@ void display_reg(int during_login)
        if (goto_config_room(Buf, &Room) != 0) {
                syslog(9, "display_reg() exiting because goto_config_room() failed\n");
                if (during_login) {
-                       do_welcome();
+                       pop_destination();
                }
                else {
                        display_main_menu();
@@ -787,7 +705,7 @@ void display_reg(int during_login)
        if (vcard_msgnum < 0L) {
                syslog(9, "display_reg() exiting because locate_user_vcard_in_this_room() failed\n");
                if (during_login) {
-                       do_welcome();
+                       pop_destination();
                }
                else {
                        display_main_menu();
@@ -796,7 +714,7 @@ void display_reg(int during_login)
        }
 
        if (during_login) {
-               do_edit_vcard(vcard_msgnum, "1", VCMsg, VCAtt, "do_welcome", USERCONFIGROOM);
+               do_edit_vcard(vcard_msgnum, "1", VCMsg, VCAtt, "pop", USERCONFIGROOM);
        }
        else {
                StrBuf *ReturnTo;
@@ -806,7 +724,6 @@ void display_reg(int during_login)
                FreeStrBuf(&ReturnTo);
        }
 
-       /* FIXME - don't we have to free VCMsg and VCAtt ?? */
 }
 
 
@@ -940,13 +857,13 @@ int ConditionalHaveAccessCreateRoom(StrBuf *Target, WCTemplputParams *TP)
 int ConditionalAide(StrBuf *Target, WCTemplputParams *TP)
 {
        wcsession *WCC = WC;
-       return (WCC != NULL)? (WC->is_aide == 0) : 0;
+       return (WCC != NULL) ? ((WCC->logged_in == 0)||(WC->is_aide == 0)) : 0;
 }
 
 int ConditionalIsLoggedIn(StrBuf *Target, WCTemplputParams *TP) 
 {
        wcsession *WCC = WC;
-       return (WCC != NULL)? (WCC->logged_in == 0) : 0;
+       return (WCC != NULL) ? (WCC->logged_in == 0) : 0;
 
 }
 
@@ -1067,9 +984,6 @@ InitModule_AUTH
 
        /* some of these will be removed soon */
        WebcitAddUrlHandler(HKEY("do_welcome"), "", 0, do_welcome, ANONYMOUS|COOKIEUNNEEDED);
-#ifdef __OLD__LOGIN__SCREEN__
-       WebcitAddUrlHandler(HKEY("login"), "", 0, do_login, ANONYMOUS|COOKIEUNNEEDED);
-#endif
        WebcitAddUrlHandler(HKEY("openid_login"), "", 0, do_openid_login, ANONYMOUS);
        WebcitAddUrlHandler(HKEY("finalize_openid_login"), "", 0, finalize_openid_login, ANONYMOUS);
        WebcitAddUrlHandler(HKEY("openid_manual_create"), "", 0, openid_manual_create, ANONYMOUS);
@@ -1080,9 +994,8 @@ InitModule_AUTH
        WebcitAddUrlHandler(HKEY("changepw"), "", 0, changepw, 0);
        WebcitAddUrlHandler(HKEY("termquit"), "", 0, do_logout, 0);
        WebcitAddUrlHandler(HKEY("do_logout"), "", 0, do_logout, ANONYMOUS|COOKIEUNNEEDED|FORCE_SESSIONCLOSE);
-       WebcitAddUrlHandler(HKEY("ajax_login_username_password"), "", 0,
-               ajax_login_username_password, AJAX|ANONYMOUS);
-
+       WebcitAddUrlHandler(HKEY("ajax_login_username_password"), "", 0, ajax_login_username_password, AJAX|ANONYMOUS);
+       WebcitAddUrlHandler(HKEY("ajax_login_newuser"), "", 0, ajax_login_newuser, AJAX|ANONYMOUS);
        RegisterConditional(HKEY("COND:AIDE"), 2, ConditionalAide, CTX_NONE);
        RegisterConditional(HKEY("COND:LOGGEDIN"), 2, ConditionalIsLoggedIn, CTX_NONE);
        RegisterConditional(HKEY("COND:MAY_CREATE_ROOM"), 2,  ConditionalHaveAccessCreateRoom, CTX_NONE);