- // Prevent access to "users pages"
- logged: function(req, res, next) {
- const callback = () => {
- if (!loggedIn)
- return res.json({errmsg: "Not logged in"});
- next();
- };
- let loggedIn = undefined;
- if (!req.cookies.token)
- {
- loggedIn = false;
- callback();
- }
- else
- {
- UserModel.getOne("sessionToken", req.cookies.token, function(err, user) {
- if (!!user)
- {
- req.userId = user.id;
- req.userName = user.name;
- loggedIn = true;
- }
- else
- {
- // Token in cookies presumably wrong: erase it
- res.clearCookie("token");
- loggedIn = false;
- }
- callback();
- });
- }
- },
+ // Prevent access to "users pages"
+ logged: function(req, res, next) {
+ const callback = () => {
+ if (!loggedIn)
+ res.json({errmsg: "Error: please delete cookies and cross fingers"});
+ else next();
+ };
+ let loggedIn = undefined;
+ if (!req.cookies.token)
+ {
+ loggedIn = false;
+ callback();
+ }
+ else
+ {
+ UserModel.getOne("sessionToken", req.cookies.token, function(err, user) {
+ if (!!user)
+ {
+ req.userId = user.id;
+ req.userName = user.name;
+ loggedIn = true;
+ }
+ else
+ {
+ // Token in cookies presumably wrong: erase it
+ res.clearCookie("token");
+ loggedIn = false;
+ }
+ callback();
+ });
+ }
+ },