Initial version of modal login is now working.
[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  * Wrapper script to require logging in before completing an action
11  */
12 function GetLoggedInFirst(destination_url) {
13
14         /* If logged in already, go directly to the destination. */
15         /* FIXME implement this */
16
17         /* If not logged in, go modal and ask the user to log in first. */
18         p = 'do_template?template=get_logged_in?destination_url=' + destination_url;
19         new Ajax.Updater(
20                 'md-content',
21                 p,
22                 {
23                         method: 'get',
24                         onSuccess: function(cl_success) {
25                                 toggleModal(1);
26                         }
27                 }
28         );
29 }
30
31
32 /*
33  * Attempt login with username/password, called from modal dialog
34  */
35 function ajax_try_username_and_password(destination_url) {
36         $('login_errmsg').innerHTML = "";
37         $('ajax_username_password_form').request({
38                 onSuccess: function(ctdlresult) {
39                         if (ctdlresult.responseText.substr(0,1) == '2') {
40                                 window.location = destination_url;
41                         }
42                         else {
43                                 $('login_errmsg').innerHTML = ctdlresult.responseText.substr(4) ;
44                         }
45                 }
46         });
47 }