mirror of https://github.com/calzoneman/sync.git
Modifications for ip session cookie
This commit is contained in:
parent
74cb1b3efc
commit
0327b3de2e
10
src/user.js
10
src/user.js
|
@ -450,15 +450,15 @@ User.prototype.refreshAccount = function (cb) {
|
||||||
};
|
};
|
||||||
|
|
||||||
User.prototype.getFirstSeenTime = function getFirstSeenTime() {
|
User.prototype.getFirstSeenTime = function getFirstSeenTime() {
|
||||||
if (this.registrationTime && this.socket.ipReputation && this.socket.ipReputation.first_seen) {
|
if (this.registrationTime && this.socket.ipSessionFirstSeen) {
|
||||||
return Math.min(this.registrationTime.getTime(), this.socket.ipReputation.first_seen.getTime());
|
return Math.min(this.registrationTime.getTime(), this.socket.ipSessionFirstSeen);
|
||||||
} else if (this.registrationTime) {
|
} else if (this.registrationTime) {
|
||||||
return this.registrationTime.getTime();
|
return this.registrationTime.getTime();
|
||||||
} else if (this.socket.ipReputation && this.socket.ipReputation.first_seen) {
|
} else if (this.socket.ipSessionFirstSeen) {
|
||||||
return this.socket.ipReputation.first_seen.getTime();
|
return this.socket.ipSessionFirstSeen;
|
||||||
} else {
|
} else {
|
||||||
Logger.errlog.log(`User "${this.getName()}" (IP: ${this.realip}) has neither ` +
|
Logger.errlog.log(`User "${this.getName()}" (IP: ${this.realip}) has neither ` +
|
||||||
"an IP reputation nor a registered account.");
|
"an IP sesion first seen time nor a registered account.");
|
||||||
return Date.now();
|
return Date.now();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -4,6 +4,7 @@ import crypto from 'crypto';
|
||||||
|
|
||||||
const SALT_PATH = path.resolve(__dirname, '..', '..', '..', 'state', 'ipsessionsalt.json');
|
const SALT_PATH = path.resolve(__dirname, '..', '..', '..', 'state', 'ipsessionsalt.json');
|
||||||
|
|
||||||
|
const NO_EXPIRATION = new Date('Fri, 31 Dec 9999 23:59:59 GMT');
|
||||||
var SALT;
|
var SALT;
|
||||||
try {
|
try {
|
||||||
SALT = require(SALT_PATH);
|
SALT = require(SALT_PATH);
|
||||||
|
@ -67,7 +68,8 @@ export function ipSessionCookieMiddleware(req, res, next) {
|
||||||
if (!hasSession) {
|
if (!hasSession) {
|
||||||
res.cookie('ip-session', createIPSessionCookie(req.realIP, firstSeen), {
|
res.cookie('ip-session', createIPSessionCookie(req.realIP, firstSeen), {
|
||||||
signed: true,
|
signed: true,
|
||||||
httpOnly: true
|
httpOnly: true,
|
||||||
|
expires: NO_EXPIRATION
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue