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 $(show_which_div).style.display = 'block';
68 * Pop out a window for external auth methods
69 * (most of them don't handle inline auth very well)
71 function do_auth_popout(popout_url) {
72 window.open(popout_url, "authpopout", "status=1,toolbar=0,width=600,height=400");
78 /****************** USERNAME AND PASSWORD ***********************/
81 * Attempt login with username/password, called from modal dialog
83 function ajax_try_username_and_password() {
85 $('login_errmsg').innerHTML = "";
86 $('ajax_username_password_form').request({
87 onSuccess: function(ctdlresult) {
88 if (ctdlresult.responseText.substr(0,1) == '2') {
89 window.location = 'pop';
92 $('login_errmsg').innerHTML = ctdlresult.responseText.substr(4) ;
100 * The user pressed a key while in the username or password box.
101 * Is it the enter/return key? Submit the form.
103 function username_and_password_onkeypress(e) {
104 if (window.event) { /* IE */
107 else if (e.which) { /* real browsers */
110 if (keynum == 13) { /* enter/return key */
111 ajax_try_username_and_password();
116 /****************** REGISTER NEW USER ***********************/
119 * Attempt to create a new local username/password, called from modal dialog
121 function ajax_try_newuser() {
123 $('login_errmsg').innerHTML = "";
124 $('ajax_newuser_form').request({
125 onSuccess: function(ctdlresult) {
126 if (ctdlresult.responseText.substr(0,1) == '2') {
127 window.location = 'pop';
130 $('login_errmsg').innerHTML = ctdlresult.responseText.substr(4) ;
138 * The user pressed a key while in the newuser or newpassword box.
139 * Is it the enter/return key? Submit the form.
141 function newuser_onkeypress(e) {
142 if (window.event) { /* IE */
145 else if (e.which) { /* real browsers */
148 if (keynum == 13) { /* enter/return key */
156 /****************** OPENID ***********************/
159 * Attempt login with OpenID, called from modal dialog
161 function ajax_try_openid() {
162 $('login_errmsg').innerHTML = "";
163 openid_url = encodeURI($('ajax_openid_form').elements["openid_url"].value);
164 do_auth_popout("openid_login?openid_url=" + openid_url);
169 * The user pressed a key while in the openid login box.
170 * Is it the enter/return key? Submit the form.
172 function openid_onkeypress(e) {
173 if (window.event) { /* IE */
176 else if (e.which) { /* real browsers */
179 if (keynum == 13) { /* enter/return key */
187 /****************** GOOGLE ***********************/
190 * Attempt login with Google, called from modal dialog
192 function ajax_try_google() {
193 $('login_errmsg').innerHTML = "";
194 openid_url = encodeURI("https://www.google.com/accounts/o8/id");
195 do_auth_popout("openid_login?openid_url=" + openid_url);
199 /****************** GOOGLE ***********************/
202 * Attempt login with Google, called from modal dialog
204 function ajax_try_yahoo() {
205 $('login_errmsg').innerHTML = "";
206 openid_url = encodeURI("http://yahoo.com");
207 do_auth_popout("openid_login?openid_url=" + openid_url);