2 * Copyright 2010, the Citadel Team
3 * Licensed under the GPL V3
5 * JavaScript functions which handle various authentication methods.
10 * Are we logged in right now?
12 function IsLoggedIn() {
13 if ($('is_logged_in').innerHTML == "yes") {
24 * Wrapper script to require logging in before completing an action
26 function GetLoggedInFirst(destination_url) {
28 /* If logged in already, go directly to the destination. */
30 window.location = decodeURIComponent(destination_url);
34 p = 'push?url=' + destination_url;
35 new Ajax.Request(p, { method: 'get' } );
37 /* If not logged in, go modal and ask the user to log in first. */
40 'do_template?template=get_logged_in',
43 onSuccess: function() {
52 * Attempt login with username/password, called from modal dialog
54 function ajax_try_username_and_password() {
56 $('login_errmsg').innerHTML = "";
57 $('ajax_username_password_form').request({
58 onSuccess: function(ctdlresult) {
59 if (ctdlresult.responseText.substr(0,1) == '2') {
60 window.location = 'pop';
63 $('login_errmsg').innerHTML = ctdlresult.responseText.substr(4) ;
70 * The user pressed a key while in the username or password box.
71 * Is it the enter/return key? Submit the form.
73 function username_and_password_onkeypress(e) {
74 if (window.event) { /* IE */
77 else if (e.which) { /* real browsers */
80 if (keynum == 13) { /* enter/return key */
81 ajax_try_username_and_password();
87 * tab handler for the login box
89 function authtoggle(show_which_div) {
90 $('authbox_userpass').style.display = 'none';
91 $('authbox_openid').style.display = 'none';
92 $(show_which_div).style.display = 'block';