fix dlen
[citadel.git] / webcit / static / authmethods.js
index 8ad1e29fa14c44cb5d7bc9af8a2e29c4e3d799a3..fa17b7351f0764e26c567d1e19d0d749f94c423b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2010-2011, the Citadel Team
+ * Copyright 2010-2017, the Citadel Team
  * Licensed under the GPL V3
  *
  * JavaScript functions which handle various authentication methods.
@@ -38,16 +38,7 @@ function GetLoggedInFirst(destination_url) {
        new Ajax.Request(p, { method: 'get' } );
 
        /* If not logged in, go modal and ask the user to log in first. */
-       new Ajax.Updater(
-               'md-content',
-               'do_template?template=get_logged_in',
-                {
-                        method: 'get',
-                       onSuccess: function() {
-                               toggleModal(1);
-                       }
-                }
-        );
+        toggleModal(1);
 }
 
 
@@ -58,6 +49,10 @@ function authtoggle(show_which_div) {
        $('authbox_userpass').style.display = 'none';
        $('authbox_newuser').style.display = 'none';
        $('authbox_openid').style.display = 'none';
+       $('authbox_google').style.display = 'none';
+       $('authbox_yahoo').style.display = 'none';
+       $('authbox_aol').style.display = 'none';
+       $('authbox_success').style.display = 'none';
        $(show_which_div).style.display = 'block';
 }
 
@@ -81,6 +76,7 @@ function do_auth_popout(popout_url) {
 function ajax_try_username_and_password() {
 
        $('login_errmsg').innerHTML = "";
+       authtoggle('authbox_success');
         $('ajax_username_password_form').request({
                onSuccess: function(ctdlresult) {
                        if (ctdlresult.responseText.substr(0,1) == '2') {
@@ -88,6 +84,7 @@ function ajax_try_username_and_password() {
                        }
                        else {
                                $('login_errmsg').innerHTML = ctdlresult.responseText.substr(4) ;
+                               authtoggle('authbox_userpass');
                        }
                }
        });
@@ -122,6 +119,7 @@ function ajax_try_newuser() {
         $('ajax_newuser_form').request({
                onSuccess: function(ctdlresult) {
                        if (ctdlresult.responseText.substr(0,1) == '2') {
+                               authtoggle('authbox_success');
                                window.location = 'pop';
                        }
                        else {
@@ -176,7 +174,64 @@ function openid_onkeypress(e) {
        }
        if (keynum == 13) {             /* enter/return key */
                ajax_try_openid();
+               return false;
+       }
+       return true;
+}
+
+
+/****************** GOOGLE ***********************/
+
+/*
+ * Attempt login with Google, called from modal dialog
+ */
+function ajax_try_google() {
+       $('login_errmsg').innerHTML = "";
+       openid_url = encodeURI("https://www.google.com/accounts/o8/id");
+       do_auth_popout("openid_login?openid_url=" + openid_url);
+}
+
+
+/****************** YAHOO ***********************/
+
+/*
+ * Attempt login with Yahoo, called from modal dialog
+ */
+function ajax_try_yahoo() {
+       $('login_errmsg').innerHTML = "";
+       openid_url = encodeURI("http://yahoo.com");
+       do_auth_popout("openid_login?openid_url=" + openid_url);
+}
+
+
+/****************** AOL ***********************/
+
+/*
+ * Attempt login with AOL, called from modal dialog
+ */
+function ajax_try_aol() {
+       $('login_errmsg').innerHTML = "";
+       openid_url = encodeURI($('ajax_aol_form').elements["aol_screenname"].value);
+       do_auth_popout("openid_login?openid_url=http://openid.aol.com/" + openid_url);
+}
+
+
+/*
+ * The user pressed a key while in the AOL login box.
+ * Is it the enter/return key?  Submit the form.
+ */
+function aol_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_aol();
+               return false;
        }
+       return true;
 }