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 $('authbox_google').style.display = 'none';
62 $('authbox_yahoo').style.display = 'none';
63 $('authbox_aol').style.display = 'none';
64 $('authbox_success').style.display = 'none';
65 $(show_which_div).style.display = 'block';
70 * Pop out a window for external auth methods
71 * (most of them don't handle inline auth very well)
73 function do_auth_popout(popout_url) {
74 window.open(popout_url, "authpopout", "status=1,toolbar=0,width=600,height=400");
80 /****************** USERNAME AND PASSWORD ***********************/
83 * Attempt login with username/password, called from modal dialog
85 function ajax_try_username_and_password() {
87 $('login_errmsg').innerHTML = "";
88 authtoggle('authbox_success');
89 $('ajax_username_password_form').request({
90 onSuccess: function(ctdlresult) {
91 if (ctdlresult.responseText.substr(0,1) == '2') {
92 window.location = 'pop';
95 $('login_errmsg').innerHTML = ctdlresult.responseText.substr(4) ;
103 * The user pressed a key while in the username or password box.
104 * Is it the enter/return key? Submit the form.
106 function username_and_password_onkeypress(e) {
107 if (window.event) { /* IE */
110 else if (e.which) { /* real browsers */
113 if (keynum == 13) { /* enter/return key */
114 ajax_try_username_and_password();
119 /****************** REGISTER NEW USER ***********************/
122 * Attempt to create a new local username/password, called from modal dialog
124 function ajax_try_newuser() {
126 $('login_errmsg').innerHTML = "";
127 $('ajax_newuser_form').request({
128 onSuccess: function(ctdlresult) {
129 if (ctdlresult.responseText.substr(0,1) == '2') {
130 authtoggle('authbox_success');
131 window.location = 'pop';
134 $('login_errmsg').innerHTML = ctdlresult.responseText.substr(4) ;
142 * The user pressed a key while in the newuser or newpassword box.
143 * Is it the enter/return key? Submit the form.
145 function newuser_onkeypress(e) {
146 if (window.event) { /* IE */
149 else if (e.which) { /* real browsers */
152 if (keynum == 13) { /* enter/return key */
160 /****************** OPENID ***********************/
163 * Attempt login with OpenID, called from modal dialog
165 function ajax_try_openid() {
166 $('login_errmsg').innerHTML = "";
167 openid_url = encodeURI($('ajax_openid_form').elements["openid_url"].value);
168 do_auth_popout("openid_login?openid_url=" + openid_url);
173 * The user pressed a key while in the openid login box.
174 * Is it the enter/return key? Submit the form.
176 function openid_onkeypress(e) {
177 if (window.event) { /* IE */
180 else if (e.which) { /* real browsers */
183 if (keynum == 13) { /* enter/return key */
191 /****************** GOOGLE ***********************/
194 * Attempt login with Google, called from modal dialog
196 function ajax_try_google() {
197 $('login_errmsg').innerHTML = "";
198 openid_url = encodeURI("https://www.google.com/accounts/o8/id");
199 do_auth_popout("openid_login?openid_url=" + openid_url);
203 /****************** GOOGLE ***********************/
206 * Attempt login with Yahoo, called from modal dialog
208 function ajax_try_yahoo() {
209 $('login_errmsg').innerHTML = "";
210 openid_url = encodeURI("http://yahoo.com");
211 do_auth_popout("openid_login?openid_url=" + openid_url);
215 /****************** AOL ***********************/
218 * Attempt login with AOL, called from modal dialog
220 function ajax_try_aol() {
221 $('login_errmsg').innerHTML = "";
222 openid_url = encodeURI($('ajax_aol_form').elements["aol_screenname"].value);
223 do_auth_popout("openid_login?openid_url=http://openid.aol.com/" + openid_url);
228 * The user pressed a key while in the AOL login box.
229 * Is it the enter/return key? Submit the form.
231 function aol_onkeypress(e) {
232 if (window.event) { /* IE */
235 else if (e.which) { /* real browsers */
238 if (keynum == 13) { /* enter/return key */