Applied the GetLoggedInFirst() semantics to the Reply buttons
[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         /* If not logged in, go modal and ask the user to log in first. */
35         p = 'do_template?template=get_logged_in?destination_url=' + destination_url;
36         new Ajax.Updater(
37                 'md-content',
38                 p,
39                 {
40                         method: 'get',
41                         onSuccess: function(cl_success) {
42                                 toggleModal(1);
43                         }
44                 }
45         );
46 }
47
48
49 /*
50  * Attempt login with username/password, called from modal dialog
51  */
52 function ajax_try_username_and_password(destination_url) {
53
54         $('login_errmsg').innerHTML = "";
55         $('ajax_username_password_form').request({
56                 onSuccess: function(ctdlresult) {
57                         if (ctdlresult.responseText.substr(0,1) == '2') {
58                                 window.location = decodeURIComponent(destination_url);
59                         }
60                         else {
61                                 $('login_errmsg').innerHTML = ctdlresult.responseText.substr(4) ;
62                         }
63                 }
64         });
65 }
66
67 /*
68  * tab handler for the login box
69  */
70 function authtoggle(show_which_div) {
71         $('authbox_userpass').style.display = 'none';
72         $('authbox_openid').style.display = 'none';
73         $(show_which_div).style.display = 'block';
74 }