1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237
|
/*
* 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?
*/
function IsLoggedIn() {
if ($('is_logged_in').innerHTML == "yes") {
return 1;
}
else {
return 0;
}
}
/*
* Wrapper script to require logging in before completing an action
*/
function GetLoggedInFirst(destination_url) {
/* If logged in already, go directly to the destination. */
if (IsLoggedIn()) {
window.location = decodeURIComponent(destination_url);
return;
}
p = 'push?url=' + destination_url;
new Ajax.Request(p, { method: 'get' } );
/* If not logged in, go modal and ask the user to log in first. */
toggleModal(1);
}
/*
* 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';
$('authbox_success').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
*/
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') {
window.location = 'pop';
}
else {
$('login_errmsg').innerHTML = ctdlresult.responseText.substr(4) ;
authtoggle('authbox_userpass');
}
}
});
}
/*
* The user pressed a key while in the username or password box.
* Is it the enter/return key? Submit the form.
*/
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') {
authtoggle('authbox_success');
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;
}
|