2 * Copyright 2010-2017, 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. */
46 * tab handler for the login box
48 function authtoggle(show_which_div) {
49 $('authbox_userpass').style.display = 'none';
50 $('authbox_newuser').style.display = 'none';
51 $('authbox_openid').style.display = 'none';
52 $('authbox_google').style.display = 'none';
53 $('authbox_yahoo').style.display = 'none';
54 $('authbox_aol').style.display = 'none';
55 $('authbox_success').style.display = 'none';
56 $(show_which_div).style.display = 'block';
61 * Pop out a window for external auth methods
62 * (most of them don't handle inline auth very well)
64 function do_auth_popout(popout_url) {
65 window.open(popout_url, "authpopout", "status=1,toolbar=0,width=600,height=400");
71 /****************** USERNAME AND PASSWORD ***********************/
74 * Attempt login with username/password, called from modal dialog
76 function ajax_try_username_and_password() {
78 $('login_errmsg').innerHTML = "";
79 authtoggle('authbox_success');
80 $('ajax_username_password_form').request({
81 onSuccess: function(ctdlresult) {
82 if (ctdlresult.responseText.substr(0,1) == '2') {
83 window.location = 'pop';
86 $('login_errmsg').innerHTML = ctdlresult.responseText.substr(4) ;
87 authtoggle('authbox_userpass');
95 * The user pressed a key while in the username or password box.
96 * Is it the enter/return key? Submit the form.
98 function username_and_password_onkeypress(e) {
99 if (window.event) { /* IE */
102 else if (e.which) { /* real browsers */
105 if (keynum == 13) { /* enter/return key */
106 ajax_try_username_and_password();
111 /****************** REGISTER NEW USER ***********************/
114 * Attempt to create a new local username/password, called from modal dialog
116 function ajax_try_newuser() {
118 $('login_errmsg').innerHTML = "";
119 $('ajax_newuser_form').request({
120 onSuccess: function(ctdlresult) {
121 if (ctdlresult.responseText.substr(0,1) == '2') {
122 authtoggle('authbox_success');
123 window.location = 'pop';
126 $('login_errmsg').innerHTML = ctdlresult.responseText.substr(4) ;
134 * The user pressed a key while in the newuser or newpassword box.
135 * Is it the enter/return key? Submit the form.
137 function newuser_onkeypress(e) {
138 if (window.event) { /* IE */
141 else if (e.which) { /* real browsers */
144 if (keynum == 13) { /* enter/return key */
152 /****************** OPENID ***********************/
155 * Attempt login with OpenID, called from modal dialog
157 function ajax_try_openid() {
158 $('login_errmsg').innerHTML = "";
159 openid_url = encodeURI($('ajax_openid_form').elements["openid_url"].value);
160 do_auth_popout("openid_login?openid_url=" + openid_url);
165 * The user pressed a key while in the openid login box.
166 * Is it the enter/return key? Submit the form.
168 function openid_onkeypress(e) {
169 if (window.event) { /* IE */
172 else if (e.which) { /* real browsers */
175 if (keynum == 13) { /* enter/return key */
183 /****************** GOOGLE ***********************/
186 * Attempt login with Google, called from modal dialog
188 function ajax_try_google() {
189 $('login_errmsg').innerHTML = "";
190 openid_url = encodeURI("https://www.google.com/accounts/o8/id");
191 do_auth_popout("openid_login?openid_url=" + openid_url);
195 /****************** YAHOO ***********************/
198 * Attempt login with Yahoo, called from modal dialog
200 function ajax_try_yahoo() {
201 $('login_errmsg').innerHTML = "";
202 openid_url = encodeURI("http://yahoo.com");
203 do_auth_popout("openid_login?openid_url=" + openid_url);
207 /****************** AOL ***********************/
210 * Attempt login with AOL, called from modal dialog
212 function ajax_try_aol() {
213 $('login_errmsg').innerHTML = "";
214 openid_url = encodeURI($('ajax_aol_form').elements["aol_screenname"].value);
215 do_auth_popout("openid_login?openid_url=http://openid.aol.com/" + openid_url);
220 * The user pressed a key while in the AOL login box.
221 * Is it the enter/return key? Submit the form.
223 function aol_onkeypress(e) {
224 if (window.event) { /* IE */
227 else if (e.which) { /* real browsers */
230 if (keynum == 13) { /* enter/return key */