X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=webcit%2Fstatic%2Fauthmethods.js;h=ef800dd4ea668604975fcbea93f8e8878a128054;hb=f761d3d44a41dd9313924cd418bec4cde39efc1a;hp=67018a7c2aaef8f59d639bc629f1289b371e5db2;hpb=3b487ee678aeede9b1071798ea19d688c047e3aa;p=citadel.git diff --git a/webcit/static/authmethods.js b/webcit/static/authmethods.js index 67018a7c2..ef800dd4e 100644 --- a/webcit/static/authmethods.js +++ b/webcit/static/authmethods.js @@ -1,11 +1,15 @@ /* - * Copyright 2010, the Citadel Team + * Copyright 2010-2011, the Citadel Team * Licensed under the GPL V3 * * JavaScript functions which handle various authentication methods. */ + +/****************** COMMON CODE ***********************/ + + /* * Are we logged in right now? */ @@ -19,7 +23,6 @@ function IsLoggedIn() { } - /* * Wrapper script to require logging in before completing an action */ @@ -48,6 +51,33 @@ 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'; + $('authbox_google').style.display = 'none'; + $('authbox_yahoo').style.display = 'none'; + $('authbox_aol').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 */ @@ -66,11 +96,147 @@ function ajax_try_username_and_password() { }); } + /* - * tab handler for the login box + * The user pressed a key while in the username or password box. + * Is it the enter/return key? Submit the form. */ -function authtoggle(show_which_div) { - $('authbox_userpass').style.display = 'none'; - $('authbox_openid').style.display = 'none'; - $(show_which_div).style.display = 'block'; +function username_and_password_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_username_and_password(); + } +} + + +/****************** REGISTER NEW USER ***********************/ + +/* + * Attempt to create a new local username/password, called from modal dialog + */ +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) ; + } + } + }); +} + + +/* + * The user pressed a key while in the newuser or newpassword box. + * Is it the enter/return key? Submit the form. + */ +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 + */ +function ajax_try_openid() { + $('login_errmsg').innerHTML = ""; + openid_url = encodeURI($('ajax_openid_form').elements["openid_url"].value); + do_auth_popout("openid_login?openid_url=" + openid_url); +} + + +/* + * The user pressed a key while in the openid login box. + * Is it the enter/return key? Submit the form. + */ +function openid_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_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); +} + + +/****************** GOOGLE ***********************/ + +/* + * 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; +} + +