Disabled the old login screen.
[citadel.git] / webcit / static / authmethods.js
1 /*
2  * Copyright 2010-2011, 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  * Wrapper script to require logging in before completing an action
24  */
25 function GetLoggedInFirst(destination_url) {
26
27         /* If logged in already, go directly to the destination. */
28         if (IsLoggedIn()) {
29                 window.location = decodeURIComponent(destination_url);
30                 return;
31         }
32
33         p = 'push?url=' + destination_url;
34         new Ajax.Request(p, { method: 'get' } );
35
36         /* If not logged in, go modal and ask the user to log in first. */
37         new Ajax.Updater(
38                 'md-content',
39                 'do_template?template=get_logged_in',
40                 {
41                         method: 'get',
42                         onSuccess: function() {
43                                 toggleModal(1);
44                         }
45                 }
46         );
47 }
48
49
50 /*
51  * Attempt login with username/password, called from modal dialog
52  */
53 function ajax_try_username_and_password() {
54
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';
60                         }
61                         else {
62                                 $('login_errmsg').innerHTML = ctdlresult.responseText.substr(4) ;
63                         }
64                 }
65         });
66 }
67
68
69 /*
70  * The user pressed a key while in the username or password box.
71  * Is it the enter/return key?  Submit the form.
72  */
73 function username_and_password_onkeypress(e) {
74         if (window.event) {             /* IE */
75                 keynum = e.keyCode
76         }
77         else if (e.which) {             /* real browsers */
78                 keynum = e.which
79         }
80         if (keynum == 13) {             /* enter/return key */
81                 ajax_try_username_and_password();
82         }
83 }
84
85
86 /*
87  * tab handler for the login box
88  */
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';
93 }
94
95
96 /*
97  * Pop out a window for external auth methods
98  * (most of them don't handle inline auth very well)
99  */
100 function do_auth_popout(popout_url) {
101         window.open(popout_url, "authpopout", "status=1,toolbar=0,width=600,height=400");
102 }
103
104
105 /*
106  * Attempt login with OpenID, called from modal dialog
107  */
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);
112 }