- Create Newsletter Page: MailingList (without the class style, using Gulp tasks)#94

This commit is contained in:
Paolo Arena
2019-11-21 00:18:40 +01:00
parent 20a3120054
commit f7fa0c4909
54 changed files with 675 additions and 51 deletions

View File

@@ -0,0 +1,62 @@
const server_constants = require('../tools/server_constants');
var {User} = require('../models/user');
const tools = require('../tools/general');
const authenticate = (req, res, next) => {
const token = req.header('x-auth');
// console.log('authenticate... ');
const access = 'auth';
User.findByToken(token, access).then((user) => {
if (!user) {
tools.mylog("TOKEN " + token);
tools.mylog(" NOT FOUND! (Maybe Connected to other Page) ACCESS: '" + access + "'");
return Promise.reject(server_constants.RIS_CODE_HTTP_INVALID_TOKEN);
// res.status().send();
}
// Save last time online
user.lasttimeonline = new Date();
return user.save().then(() => {
req.user = user;
req.token = token;
req.access = access;
next();
});
// tools.mylog('userid', user._id);
}).catch((e) => {
tools.mylog("ERR =", e);
res.status(server_constants.RIS_CODE_HTTP_INVALID_TOKEN).send();
});
};
const authenticate_noerror = (req, res, next) => {
const token = req.header('x-auth');
const access = 'auth';
User.findByToken(token, access).then((user) => {
if (!user) {
req.user = null;
req.token = null;
req.access = null;
}else {
req.user = user;
req.token = token;
req.access = access;
}
next();
}).catch((e) => {
req.user = null;
req.token = null;
req.access = null;
});
};
module.exports = {authenticate, authenticate_noerror};