Options page: handle not being logged in.
The options page now displays whether or not the user is logged in.
This commit is contained in:
parent
eb2e44e13e
commit
a1f56007d0
3 changed files with 23 additions and 4 deletions
21
options.js
21
options.js
|
|
@ -1,20 +1,33 @@
|
|||
function setup() {
|
||||
if (!("lcred" in sessionStorage))
|
||||
if (!("lcred" in sessionStorage)) {
|
||||
setstatus("You are not logged in.");
|
||||
return;
|
||||
}
|
||||
var url = "/uinfo/email?key=" + sessionStorage.getItem("lcred");
|
||||
var req = new XMLHttpRequest();
|
||||
req.onreadystatechange = function () {
|
||||
if (req.readyState != 4 || req.status != 200)
|
||||
return;
|
||||
var reply = JSON.parse(req.responseText);
|
||||
if (!("email" in reply))
|
||||
return;
|
||||
document.getElementById("input_email").value = reply["email"];
|
||||
if (!("email" in reply)) {
|
||||
setstatus("You are not logged in.");
|
||||
}
|
||||
else {
|
||||
setstatus("You are logged in as " + reply.u + ".");
|
||||
document.getElementById("input_email").value = reply["email"];
|
||||
document.getElementById("switch").style.display = "block";
|
||||
}
|
||||
}
|
||||
req.open('GET', url, true);
|
||||
req.send();
|
||||
}
|
||||
|
||||
function setstatus(stattext) {
|
||||
var statnode = document.createTextNode(stattext);
|
||||
var statdiv = document.getElementById("ostat");
|
||||
statdiv.replaceChild(statnode, statdiv.firstChild);
|
||||
}
|
||||
|
||||
function postemail() {
|
||||
if (!("lcred" in sessionStorage))
|
||||
return;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue