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:
John "Elwin" Edwards 2012-08-29 07:55:26 -07:00
parent eb2e44e13e
commit a1f56007d0
3 changed files with 23 additions and 4 deletions

View file

@ -7,6 +7,7 @@
</head> </head>
<body onload="setup()"> <body onload="setup()">
<h1>RLG-Web Options</h1> <h1>RLG-Web Options</h1>
<div id="ostat">Loading...</div>
<div id="switch"> <div id="switch">
<span class="ibutton">E-mail</span> <span class="ibutton">E-mail</span>
<span class="ibutton">Password</span> <span class="ibutton">Password</span>

View file

@ -1,20 +1,33 @@
function setup() { function setup() {
if (!("lcred" in sessionStorage)) if (!("lcred" in sessionStorage)) {
setstatus("You are not logged in.");
return; return;
}
var url = "/uinfo/email?key=" + sessionStorage.getItem("lcred"); var url = "/uinfo/email?key=" + sessionStorage.getItem("lcred");
var req = new XMLHttpRequest(); var req = new XMLHttpRequest();
req.onreadystatechange = function () { req.onreadystatechange = function () {
if (req.readyState != 4 || req.status != 200) if (req.readyState != 4 || req.status != 200)
return; return;
var reply = JSON.parse(req.responseText); var reply = JSON.parse(req.responseText);
if (!("email" in reply)) if (!("email" in reply)) {
return; setstatus("You are not logged in.");
document.getElementById("input_email").value = reply["email"]; }
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.open('GET', url, true);
req.send(); req.send();
} }
function setstatus(stattext) {
var statnode = document.createTextNode(stattext);
var statdiv = document.getElementById("ostat");
statdiv.replaceChild(statnode, statdiv.firstChild);
}
function postemail() { function postemail() {
if (!("lcred" in sessionStorage)) if (!("lcred" in sessionStorage))
return; return;

View file

@ -107,7 +107,12 @@ div#debug {
/* For options.html */ /* For options.html */
div#switch { div#switch {
display: none;
margin-bottom: 1em; margin-bottom: 1em;
padding: 0.4em 0.4em; padding: 0.4em 0.4em;
text-align: center; text-align: center;
} }
div#ostat {
text-align: center;
}