2 * Copyright 2010-2011, 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") {
23 * Wrapper script to require logging in before completing an action
25 function GetLoggedInFirst(destination_url) {
27 /* If logged in already, go directly to the destination. */
29 window.location = decodeURIComponent(destination_url);
33 p = 'push?url=' + destination_url;
34 new Ajax.Request(p, { method: 'get' } );
36 /* If not logged in, go modal and ask the user to log in first. */
39 'do_template?template=get_logged_in',
42 onSuccess: function() {
51 * Attempt login with username/password, called from modal dialog
53 function ajax_try_username_and_password() {
55 $('login_errmsg').innerHTML = "";
56 $('ajax_username_password_form').request({
57 onSuccess: function(ctdlresult) {
58 if (ctdlresult.responseText.substr(0,1) == '2') {
59 window.location = 'pop';
62 $('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';
97 * Pop out a window for external auth methods
98 * (most of them don't handle inline auth very well)
100 function do_auth_popout(popout_url) {
101 window.open(popout_url, "authpopout", "status=1,toolbar=0,width=600,height=400");
106 * Attempt login with OpenID, called from modal dialog
108 function ajax_try_openid() {
109 $('login_errmsg').innerHTML = "";
110 openid_url = encodeURI($('ajax_openid_form').elements["openid_url"].value);
111 do_auth_popout("openid_login?openid_url=" + openid_url);