push/pop destination_url instead of passing it through the chain
[citadel.git] / webcit / static / authmethods.js
1 /*
2  * Copyright 2010, the Citadel Team
3  * Licensed under the GPL V3
4  *
5  * JavaScript functions which handle various authentication methods.
6  */
7
8
9 /*
10  * Are we logged in right now?
11  */
12 function IsLoggedIn() {
13         if ($('is_logged_in').innerHTML == "yes") {
14                 return 1;
15         }
16         else {
17                 return 0;
18         }
19 }
20
21
22
23 /*
24  * Wrapper script to require logging in before completing an action
25  */
26 function GetLoggedInFirst(destination_url) {
27
28         /* If logged in already, go directly to the destination. */
29         if (IsLoggedIn()) {
30                 window.location = decodeURIComponent(destination_url);
31                 return;
32         }
33
34         p = 'push?url=' + destination_url;
35         new Ajax.Request(p, { method: 'get' } );
36
37         /* If not logged in, go modal and ask the user to log in first. */
38         new Ajax.Updater(
39                 'md-content',
40                 'do_template?template=get_logged_in',
41                 {
42                         method: 'get',
43                         onSuccess: function() {
44                                 toggleModal(1);
45                         }
46                 }
47         );
48 }
49
50
51 /*
52  * Attempt login with username/password, called from modal dialog
53  */
54 function ajax_try_username_and_password() {
55
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';
61                         }
62                         else {
63                                 $('login_errmsg').innerHTML = ctdlresult.responseText.substr(4) ;
64                         }
65                 }
66         });
67 }
68
69 /*
70  * tab handler for the login box
71  */
72 function authtoggle(show_which_div) {
73         $('authbox_userpass').style.display = 'none';
74         $('authbox_openid').style.display = 'none';
75         $(show_which_div).style.display = 'block';
76 }