Mercurial > hg > rlgwebd
comparison options.js @ 130:a2e071a95055
Options page: handle not being logged in.
The options page now displays whether or not the user is logged in.
author | John "Elwin" Edwards <elwin@sdf.org> |
---|---|
date | Wed, 29 Aug 2012 07:55:26 -0700 |
parents | 46822bd329da |
children | 99fbc7c55b81 |
comparison
equal
deleted
inserted
replaced
129:46822bd329da | 130:a2e071a95055 |
---|---|
1 function setup() { | 1 function setup() { |
2 if (!("lcred" in sessionStorage)) | 2 if (!("lcred" in sessionStorage)) { |
3 setstatus("You are not logged in."); | |
3 return; | 4 return; |
5 } | |
4 var url = "/uinfo/email?key=" + sessionStorage.getItem("lcred"); | 6 var url = "/uinfo/email?key=" + sessionStorage.getItem("lcred"); |
5 var req = new XMLHttpRequest(); | 7 var req = new XMLHttpRequest(); |
6 req.onreadystatechange = function () { | 8 req.onreadystatechange = function () { |
7 if (req.readyState != 4 || req.status != 200) | 9 if (req.readyState != 4 || req.status != 200) |
8 return; | 10 return; |
9 var reply = JSON.parse(req.responseText); | 11 var reply = JSON.parse(req.responseText); |
10 if (!("email" in reply)) | 12 if (!("email" in reply)) { |
11 return; | 13 setstatus("You are not logged in."); |
12 document.getElementById("input_email").value = reply["email"]; | 14 } |
15 else { | |
16 setstatus("You are logged in as " + reply.u + "."); | |
17 document.getElementById("input_email").value = reply["email"]; | |
18 document.getElementById("switch").style.display = "block"; | |
19 } | |
13 } | 20 } |
14 req.open('GET', url, true); | 21 req.open('GET', url, true); |
15 req.send(); | 22 req.send(); |
23 } | |
24 | |
25 function setstatus(stattext) { | |
26 var statnode = document.createTextNode(stattext); | |
27 var statdiv = document.getElementById("ostat"); | |
28 statdiv.replaceChild(statnode, statdiv.firstChild); | |
16 } | 29 } |
17 | 30 |
18 function postemail() { | 31 function postemail() { |
19 if (!("lcred" in sessionStorage)) | 32 if (!("lcred" in sessionStorage)) |
20 return; | 33 return; |