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) {
var name = req.body.name;
var password = req.body.password;
var rememberMe = req.body.remember;
if (typeof name !== "string" || typeof password !== "string") {
res.send(400);
@ -41,22 +42,24 @@ function handleLogin(req, res) {
});
} else {
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, {
expires: new Date(Date.now() + 7*24*60*60*1000),
expires: expiration,
httpOnly: true
});
res.cookie("auth", auth, {
domain: Config.get("http.root-domain-dotted"),
expires: new Date(Date.now() + 7*24*60*60*1000),
expires: expiration,
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
var ref = req.header("referrer");
if (!ref) {

View file

@ -35,6 +35,11 @@ html(lang="en")
label(for="password") Password
input#password.form-control(type="password", name="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
else
.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")
.form-group
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
mixin navlogoutform(redirect)