reshufflize the parameters to room renderers
[citadel.git] / webcit-ng / static / js / login.js
1 //
2 // Copyright (c) 2016-2017 by the citadel.org team
3 //
4 // This program is open source software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License version 3.
6 //
7 // This program is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10 // GNU General Public License for more details.
11
12
13 function display_login_screen(any_message)
14 {
15         document.getElementById("ctdl-main").innerHTML =
16                 "<center><br><br>Put the login screen here, dummary<br><br>" +
17                 any_message + "<br><br>" +
18                 "<table border=0><tr><td>" +
19                 _("User name:") + "</td><td><input type=\"text\" id=\"username\"></td></tr><tr><td>" +
20                 _("Password:") + "</td><td><input type=\"password\" id=\"password\"></td></tr></table><br>" +
21                 "<a href=\"javascript:login_button()\">" + _("Log in") + "</a></center>"
22         ;
23
24         update_banner();
25 }
26
27
28 function logout()
29 {
30         var request = new XMLHttpRequest();
31         request.open("GET", "/ctdl/a/logout", true);
32         request.onreadystatechange = function() {
33                 login_result(this.responseText);
34         };
35         request.send();
36         request = null;
37 }
38
39
40 function login_button(username)
41 {
42         parms = 
43                 document.getElementById("username").value
44                 + "|"
45                 + document.getElementById("password").value
46                 + "|"
47         ;
48
49         var request = new XMLHttpRequest();
50         request.open("POST", "/ctdl/a/login", true);
51         request.onreadystatechange = function() {
52                 login_result(this.responseText);
53         };
54         request.send(parms);
55         request = null;
56 }
57
58
59 function login_result(data)
60 {
61         if (data.substring(0,1) == "2") {
62                 logged_in = 1;
63                 current_user = data.substring(4).split("|")[0];
64                 update_banner();
65                 document.getElementById("ctdl-main").innerHTML = "FIXME ok we are logged in as " + current_user + " ... " ;
66         }
67         else {
68                 display_login_screen(data.substring(4));
69         }
70 }
71
72
73 // Detect whether the Citadel session is logged in as a user and update our internal variables accordingly.
74 //
75 function detect_logged_in()
76 {
77         var request = new XMLHttpRequest();
78         request.open("GET", "/ctdl/a/whoami", true);
79         request.onreadystatechange = function() {
80                 detect_logged_in_2(this.responseText);
81         };
82         request.send();
83         request = null;
84 }
85 function detect_logged_in_2(data)
86 {
87         if (data.length > 0) {
88                 logged_in = 1;
89                 current_user = data;
90         }
91         else {
92                 logged_in = 0;
93                 current_user = _("Not logged in.");
94         }
95 }