Initial 'remember me' support for logins

This commit is contained in:
calzoneman 2015-02-07 15:13:28 -06:00
parent cdcace828f
commit a31273be5c
3 changed files with 20 additions and 7 deletions

View file

@ -21,6 +21,7 @@ var url = require("url");
function handleLogin(req, res) { function handleLogin(req, res) {
var name = req.body.name; var name = req.body.name;
var password = req.body.password; var password = req.body.password;
var rememberMe = req.body.remember;
if (typeof name !== "string" || typeof password !== "string") { if (typeof name !== "string" || typeof password !== "string") {
res.send(400); res.send(400);
@ -41,22 +42,24 @@ function handleLogin(req, res) {
}); });
} else { } else {
var auth = user.name + ":" + user.hash; var auth = user.name + ":" + user.hash;
var expiration;
if (rememberMe) {
expiration = new Date("Fri, 31 Dec 9999 23:59:59 GMT");
} else {
expiration = new Date(Date.now() + 7*24*60*60*1000);
}
res.cookie("auth", auth, { res.cookie("auth", auth, {
expires: new Date(Date.now() + 7*24*60*60*1000), expires: expiration,
httpOnly: true httpOnly: true
}); });
res.cookie("auth", auth, { res.cookie("auth", auth, {
domain: Config.get("http.root-domain-dotted"), domain: Config.get("http.root-domain-dotted"),
expires: new Date(Date.now() + 7*24*60*60*1000), expires: expiration,
httpOnly: true httpOnly: true
}); });
res.cookie("rank", user.global_rank, {
domain: Config.get("http.root-domain-dotted"),
expires: new Date(Date.now() + 7*24*60*60*1000),
});
// Try to find an appropriate redirect // Try to find an appropriate redirect
var ref = req.header("referrer"); var ref = req.header("referrer");
if (!ref) { if (!ref) {

View file

@ -35,6 +35,11 @@ html(lang="en")
label(for="password") Password label(for="password") Password
input#password.form-control(type="password", name="password") input#password.form-control(type="password", name="password")
a(href="/account/passwordreset") Forgot password? a(href="/account/passwordreset") Forgot password?
.form-group
.checkbox
label
input(type="checkbox", name="remember")
| Remember me
button.btn.btn-success.btn-block(type="submit") Login button.btn.btn-success.btn-block(type="submit") Login
else else
.col-lg-6.col-lg-offset-3.col-md-6.col-md-offset-3 .col-lg-6.col-lg-offset-3.col-md-6.col-md-offset-3

View file

@ -52,6 +52,11 @@ mixin navloginform(redirect)
input#username.form-control(type="text", name="name", placeholder="Username") input#username.form-control(type="text", name="name", placeholder="Username")
.form-group .form-group
input#password.form-control(type="password", name="password", placeholder="Password") input#password.form-control(type="password", name="password", placeholder="Password")
.form-group
.checkbox
label
input(type="checkbox", name="remember")
| Remember me
button#login.btn.btn-default(type="submit") Login button#login.btn.btn-default(type="submit") Login
mixin navlogoutform(redirect) mixin navlogoutform(redirect)