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) ;
96 authtoggle('authbox_userpass');
104 * The user pressed a key while in the username or password box.
105 * Is it the enter/return key? Submit the form.
107 function username_and_password_onkeypress(e) {
108 if (window.event) { /* IE */
111 else if (e.which) { /* real browsers */
114 if (keynum == 13) { /* enter/return key */
115 ajax_try_username_and_password();
120 /****************** REGISTER NEW USER ***********************/
123 * Attempt to create a new local username/password, called from modal dialog
125 function ajax_try_newuser() {
127 $('login_errmsg').innerHTML = "";
128 $('ajax_newuser_form').request({
129 onSuccess: function(ctdlresult) {
130 if (ctdlresult.responseText.substr(0,1) == '2') {
131 authtoggle('authbox_success');
132 window.location = 'pop';
135 $('login_errmsg').innerHTML = ctdlresult.responseText.substr(4) ;
143 * The user pressed a key while in the newuser or newpassword box.
144 * Is it the enter/return key? Submit the form.
146 function newuser_onkeypress(e) {
147 if (window.event) { /* IE */
150 else if (e.which) { /* real browsers */
153 if (keynum == 13) { /* enter/return key */
161 /****************** OPENID ***********************/
164 * Attempt login with OpenID, called from modal dialog
166 function ajax_try_openid() {
167 $('login_errmsg').innerHTML = "";
168 openid_url = encodeURI($('ajax_openid_form').elements["openid_url"].value);
169 do_auth_popout("openid_login?openid_url=" + openid_url);
174 * The user pressed a key while in the openid login box.
175 * Is it the enter/return key? Submit the form.
177 function openid_onkeypress(e) {
178 if (window.event) { /* IE */
181 else if (e.which) { /* real browsers */
184 if (keynum == 13) { /* enter/return key */
192 /****************** GOOGLE ***********************/
195 * Attempt login with Google, called from modal dialog
197 function ajax_try_google() {
198 $('login_errmsg').innerHTML = "";
199 openid_url = encodeURI("https://www.google.com/accounts/o8/id");
200 do_auth_popout("openid_login?openid_url=" + openid_url);
204 /****************** GOOGLE ***********************/
207 * Attempt login with Yahoo, called from modal dialog
209 function ajax_try_yahoo() {
210 $('login_errmsg').innerHTML = "";
211 openid_url = encodeURI("http://yahoo.com");
212 do_auth_popout("openid_login?openid_url=" + openid_url);
216 /****************** AOL ***********************/
219 * Attempt login with AOL, called from modal dialog
221 function ajax_try_aol() {
222 $('login_errmsg').innerHTML = "";
223 openid_url = encodeURI($('ajax_aol_form').elements["aol_screenname"].value);
224 do_auth_popout("openid_login?openid_url=http://openid.aol.com/" + openid_url);
229 * The user pressed a key while in the AOL login box.
230 * Is it the enter/return key? Submit the form.
232 function aol_onkeypress(e) {
233 if (window.event) { /* IE */
236 else if (e.which) { /* real browsers */
239 if (keynum == 13) { /* enter/return key */