New CSS for the login modal
[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 = 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         $('login_errmsg').innerHTML = "";
54         $('ajax_username_password_form').request({
55                 onSuccess: function(ctdlresult) {
56                         if (ctdlresult.responseText.substr(0,1) == '2') {
57                                 window.location = destination_url;
58                         }
59                         else {
60                                 $('login_errmsg').innerHTML = ctdlresult.responseText.substr(4) ;
61                         }
62                 }
63         });
64 }
65
66 /*
67  * tab handler for the login box
68  */
69 function authtoggle(show_which_div) {
70         $('authbox_userpass').style.display = 'none';
71         $('authbox_openid').style.display = 'none';
72         $(show_which_div).style.display = 'block';
73 }