Files
freeplanet_serverside/server/middleware/authenticate.js
Paolo Arena 51ca2da45f - Enable Edit Event into dialog form ... (and save to the db)
- Event: enabled drag and drop (date)
- Q-Select components in every table field external: Where, Operators, etc...
- CMyEditor: Add HTML Editor to the details field !
- Added button Color for change font color to the text.
- Complete insert Events Site
2019-10-23 23:47:21 +02:00

57 lines
1.3 KiB
JavaScript

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();
}
// tools.mylog('userid', user._id);
req.user = user;
req.token = token;
req.access = access;
next();
}).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};