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 $(show_which_div).style.display = 'block';
69 * Pop out a window for external auth methods
70 * (most of them don't handle inline auth very well)
72 function do_auth_popout(popout_url) {
73 window.open(popout_url, "authpopout", "status=1,toolbar=0,width=600,height=400");
79 /****************** USERNAME AND PASSWORD ***********************/
82 * Attempt login with username/password, called from modal dialog
84 function ajax_try_username_and_password() {
86 $('login_errmsg').innerHTML = "";
87 $('ajax_username_password_form').request({
88 onSuccess: function(ctdlresult) {
89 if (ctdlresult.responseText.substr(0,1) == '2') {
90 window.location = 'pop';
93 $('login_errmsg').innerHTML = ctdlresult.responseText.substr(4) ;
101 * The user pressed a key while in the username or password box.
102 * Is it the enter/return key? Submit the form.
104 function username_and_password_onkeypress(e) {
105 if (window.event) { /* IE */
108 else if (e.which) { /* real browsers */
111 if (keynum == 13) { /* enter/return key */
112 ajax_try_username_and_password();
117 /****************** REGISTER NEW USER ***********************/
120 * Attempt to create a new local username/password, called from modal dialog
122 function ajax_try_newuser() {
124 $('login_errmsg').innerHTML = "";
125 $('ajax_newuser_form').request({
126 onSuccess: function(ctdlresult) {
127 if (ctdlresult.responseText.substr(0,1) == '2') {
128 window.location = 'pop';
131 $('login_errmsg').innerHTML = ctdlresult.responseText.substr(4) ;
139 * The user pressed a key while in the newuser or newpassword box.
140 * Is it the enter/return key? Submit the form.
142 function newuser_onkeypress(e) {
143 if (window.event) { /* IE */
146 else if (e.which) { /* real browsers */
149 if (keynum == 13) { /* enter/return key */
157 /****************** OPENID ***********************/
160 * Attempt login with OpenID, called from modal dialog
162 function ajax_try_openid() {
163 $('login_errmsg').innerHTML = "";
164 openid_url = encodeURI($('ajax_openid_form').elements["openid_url"].value);
165 do_auth_popout("openid_login?openid_url=" + openid_url);
170 * The user pressed a key while in the openid login box.
171 * Is it the enter/return key? Submit the form.
173 function openid_onkeypress(e) {
174 if (window.event) { /* IE */
177 else if (e.which) { /* real browsers */
180 if (keynum == 13) { /* enter/return key */
188 /****************** GOOGLE ***********************/
191 * Attempt login with Google, called from modal dialog
193 function ajax_try_google() {
194 $('login_errmsg').innerHTML = "";
195 openid_url = encodeURI("https://www.google.com/accounts/o8/id");
196 do_auth_popout("openid_login?openid_url=" + openid_url);
200 /****************** GOOGLE ***********************/
203 * Attempt login with Yahoo, called from modal dialog
205 function ajax_try_yahoo() {
206 $('login_errmsg').innerHTML = "";
207 openid_url = encodeURI("http://yahoo.com");
208 do_auth_popout("openid_login?openid_url=" + openid_url);
212 /****************** AOL ***********************/
215 * Attempt login with AOL, called from modal dialog
217 function ajax_try_aol() {
218 $('login_errmsg').innerHTML = "";
219 openid_url = encodeURI($('ajax_aol_form').elements["aol_screenname"].value);
220 do_auth_popout("openid_login?openid_url=http://openid.aol.com/" + openid_url);
225 * The user pressed a key while in the AOL login box.
226 * Is it the enter/return key? Submit the form.
228 function aol_onkeypress(e) {
229 if (window.event) { /* IE */
232 else if (e.which) { /* real browsers */
235 if (keynum == 13) { /* enter/return key */