2 * Copyright 2010-2011, the Citadel Team
3 * Licensed under the GPL V3
5 * JavaScript functions which handle various authentication methods.
10 /****************** COMMON CODE ***********************/
14 * Are we logged in right now?
16 function IsLoggedIn() {
17 if ($('is_logged_in').innerHTML == "yes") {
27 * Wrapper script to require logging in before completing an action
29 function GetLoggedInFirst(destination_url) {
31 /* If logged in already, go directly to the destination. */
33 window.location = decodeURIComponent(destination_url);
37 p = 'push?url=' + destination_url;
38 new Ajax.Request(p, { method: 'get' } );
40 /* If not logged in, go modal and ask the user to log in first. */
43 'do_template?template=get_logged_in',
46 onSuccess: function() {
55 * tab handler for the login box
57 function authtoggle(show_which_div) {
58 $('authbox_userpass').style.display = 'none';
59 $('authbox_newuser').style.display = 'none';
60 $('authbox_openid').style.display = 'none';
61 $(show_which_div).style.display = 'block';
66 * Pop out a window for external auth methods
67 * (most of them don't handle inline auth very well)
69 function do_auth_popout(popout_url) {
70 window.open(popout_url, "authpopout", "status=1,toolbar=0,width=600,height=400");
76 /****************** USERNAME AND PASSWORD ***********************/
79 * Attempt login with username/password, called from modal dialog
81 function ajax_try_username_and_password() {
83 $('login_errmsg').innerHTML = "";
84 $('ajax_username_password_form').request({
85 onSuccess: function(ctdlresult) {
86 if (ctdlresult.responseText.substr(0,1) == '2') {
87 window.location = 'pop';
90 $('login_errmsg').innerHTML = ctdlresult.responseText.substr(4) ;
98 * The user pressed a key while in the username or password box.
99 * Is it the enter/return key? Submit the form.
101 function username_and_password_onkeypress(e) {
102 if (window.event) { /* IE */
105 else if (e.which) { /* real browsers */
108 if (keynum == 13) { /* enter/return key */
109 ajax_try_username_and_password();
114 /****************** REGISTER NEW USER ***********************/
117 * Attempt to create a new local username/password, called from modal dialog
119 function ajax_try_newuser() {
121 $('login_errmsg').innerHTML = "";
122 $('ajax_newuser_form').request({
123 onSuccess: function(ctdlresult) {
124 if (ctdlresult.responseText.substr(0,1) == '2') {
125 window.location = 'pop';
128 $('login_errmsg').innerHTML = ctdlresult.responseText.substr(4) ;
136 * The user pressed a key while in the newuser or newpassword box.
137 * Is it the enter/return key? Submit the form.
139 function newuser_onkeypress(e) {
140 if (window.event) { /* IE */
143 else if (e.which) { /* real browsers */
146 if (keynum == 13) { /* enter/return key */
154 /****************** OPENID ***********************/
157 * Attempt login with OpenID, called from modal dialog
159 function ajax_try_openid() {
160 $('login_errmsg').innerHTML = "";
161 openid_url = encodeURI($('ajax_openid_form').elements["openid_url"].value);
162 do_auth_popout("openid_login?openid_url=" + openid_url);
167 * The user pressed a key while in the openid login box.
168 * Is it the enter/return key? Submit the form.
170 function openid_onkeypress(e) {
171 if (window.event) { /* IE */
174 else if (e.which) { /* real browsers */
177 if (keynum == 13) { /* enter/return key */