Initial version of 'register new user' dialog
authorArt Cancro <ajc@citadel.org>
Fri, 28 Jan 2011 17:50:55 +0000 (12:50 -0500)
committerWilfried Goesgens <dothebart@citadel.org>
Sun, 4 Sep 2011 14:09:54 +0000 (14:09 +0000)
webcit/auth.c
webcit/static/authmethods.js
webcit/static/styles/webcit.css
webcit/static/t/get_logged_in.html

index bbb54f32ed8781ed9fb02101330c1b4432c0aea4..6af54b88d3d3ce5e7e1912eda212294e3ce49fb0 100644 (file)
@@ -140,107 +140,39 @@ 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
+ * modal/ajax version of 'login' (username 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();
-       }
+void ajax_login_username_password(void) {
+       StrBuf *Buf = NewStrBuf();
 
-       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"));
+       serv_printf("USER %s", bstr("name"));
+       StrBuf_ServGetln(Buf);
+       if (GetServerStatus(Buf, NULL) == 3) {
+               serv_printf("PASS %s", bstr("pass"));
                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();
-       }
+
+       /* The client is expecting to read back a citadel protocol response */
+       wc_printf("%s", ChrPtr(Buf));
        FreeStrBuf(&Buf);
 }
-#endif
+
 
 
 /* 
- * modal/ajax version of 'login' (username and password)
+ * modal/ajax version of 'new user' (username and password)
  */
-void ajax_login_username_password(void) {
+void ajax_login_newuser(void) {
        StrBuf *Buf = NewStrBuf();
 
-       serv_printf("USER %s", bstr("name"));
+       serv_printf("NEWU %s", bstr("name"));
        StrBuf_ServGetln(Buf);
-       if (GetServerStatus(Buf, NULL) == 3) {
-               serv_printf("PASS %s", bstr("pass"));
+       if (GetServerStatus(Buf, NULL) == 2) {
+               serv_printf("SETP %s", bstr("pass"));
                StrBuf_ServGetln(Buf);
                if (GetServerStatus(Buf, NULL) == 2) {
                        become_logged_in(sbstr("name"), sbstr("pass"), Buf);
@@ -1067,9 +999,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 +1009,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);
index c8452c54ad3cb02b266c2834d95780baac58cd5a..fca4cf2664538741c0c17a17e4b0442d904b0191 100644 (file)
@@ -6,6 +6,10 @@
  */
 
 
+
+/****************** COMMON CODE ***********************/
+
+
 /*
  * Are we logged in right now?
  */
@@ -47,6 +51,30 @@ function GetLoggedInFirst(destination_url) {
 }
 
 
+/*
+ * tab handler for the login box
+ */
+function authtoggle(show_which_div) {
+       $('authbox_userpass').style.display = 'none';
+       $('authbox_newuser').style.display = 'none';
+       $('authbox_openid').style.display = 'none';
+       $(show_which_div).style.display = 'block';
+}
+
+
+/*
+ * Pop out a window for external auth methods
+ * (most of them don't handle inline auth very well)
+ */
+function do_auth_popout(popout_url) {
+       window.open(popout_url, "authpopout", "status=1,toolbar=0,width=600,height=400");
+}
+
+
+
+
+/****************** USERNAME AND PASSWORD ***********************/
+
 /*
  * Attempt login with username/password, called from modal dialog
  */
@@ -83,25 +111,48 @@ function username_and_password_onkeypress(e) {
 }
 
 
+/****************** REGISTER NEW USER ***********************/
+
 /*
- * tab handler for the login box
+ * Attempt to create a new local username/password, called from modal dialog
  */
-function authtoggle(show_which_div) {
-       $('authbox_userpass').style.display = 'none';
-       $('authbox_openid').style.display = 'none';
-       $(show_which_div).style.display = 'block';
+function ajax_try_newuser() {
+
+       $('login_errmsg').innerHTML = "";
+        $('ajax_newuser_form').request({
+               onSuccess: function(ctdlresult) {
+                       if (ctdlresult.responseText.substr(0,1) == '2') {
+                               window.location = 'pop';
+                       }
+                       else {
+                               $('login_errmsg').innerHTML = ctdlresult.responseText.substr(4) ;
+                       }
+               }
+       });
 }
 
 
 /*
- * Pop out a window for external auth methods
- * (most of them don't handle inline auth very well)
+ * The user pressed a key while in the newuser or newpassword box.
+ * Is it the enter/return key?  Submit the form.
  */
-function do_auth_popout(popout_url) {
-       window.open(popout_url, "authpopout", "status=1,toolbar=0,width=600,height=400");
+function newuser_onkeypress(e) {
+       if (window.event) {             /* IE */
+               keynum = e.keyCode
+       }
+       else if (e.which) {             /* real browsers */
+               keynum = e.which
+       }
+       if (keynum == 13) {             /* enter/return key */
+               ajax_try_newuser();
+       }
 }
 
 
+
+
+/****************** OPENID ***********************/
+
 /*
  * Attempt login with OpenID, called from modal dialog
  */
@@ -110,3 +161,6 @@ function ajax_try_openid() {
        openid_url = encodeURI($('ajax_openid_form').elements["openid_url"].value);
        do_auth_popout("openid_login?openid_url=" + openid_url);
 }
+
+
+
index a98e94b1c3998ea509ab8272ff659edb67b28451..8440aeeee4c89b6ba349e665adf36342a3866ab0 100644 (file)
@@ -1352,12 +1352,12 @@ a.event_title:hover span.bttbottom, a.event_unread:hover span.bttbottom, a.event
        background-color: #ddd;
 }
 
-#ajax_username_password_form {
+#ajax_username_password_form, #ajax_newuser_form {
        margin: auto;
        width: 20em;
 }
 
-#ajax_username_password_form label {
+#ajax_username_password_form label, #ajax_newuser_form label {
        float: left;
        width: 10em;
 }
index 9a7ae0f21d9fefd49a7441f5c3a32cf249a3dd61..88bbb424354fcfaca36ea50b858973bb52e016ed 100644 (file)
 <br><br>
 </form>
 <div class="logbuttons"><a href="javascript:ajax_try_username_and_password();"><?_("Log in")></a></div>
-<div class="registernow"><a href="javascript:alert('FIXME');"><?_("New user?  Register now")></a></div>
+<div class="registernow"><a href="javascript:authtoggle('authbox_newuser');"><?_("New user?  Register now")></a></div>
+</div>
+
+<div class="authbox" id="authbox_newuser" style="display: none">
+<h2><?_("New user?  Register now")></h2>
+<form id="ajax_newuser_form" method="POST" action="ajax_login_newuser">
+<label for="uname"><?_("User name:")></label>
+<input type="text" name="name" id="uname" onKeyPress="newuser_onkeypress(event);">
+<br><br>
+<label for="pname"><?_("Password:")></label>
+<input type="password" name="pass" id="pname" onKeyPress="newuser_onkeypress(event);">
+<br><br>
+</form>
+<div class="logbuttons"><a href="javascript:ajax_try_newuser();"><?_("Log in")></a></div>
 </div>
 
 <div class="authbox" id="authbox_openid" style="display: none">