Initial 'remember me' support for logins
This commit is contained in:
parent
cdcace828f
commit
a31273be5c
3 changed files with 20 additions and 7 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue