projects
/
vchess.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Reorganize and completed board component. Now need to finish game component
[vchess.git]
/
app.js
diff --git
a/app.js
b/app.js
index
22c220b
..
e63aca4
100644
(file)
--- a/
app.js
+++ b/
app.js
@@
-5,6
+5,7
@@
var cookieParser = require('cookie-parser');
var logger = require('morgan');
var sassMiddleware = require('node-sass-middleware');
var favicon = require('serve-favicon');
var logger = require('morgan');
var sassMiddleware = require('node-sass-middleware');
var favicon = require('serve-favicon');
+var UserModel = require(path.join(__dirname, "models", "User"));
var app = express();
var app = express();
@@
-45,21
+46,26
@@
app.use(express.static(path.join(__dirname, 'public')));
// Before showing any page, check + save credentials
app.use(function(req, res, next) {
// Before showing any page, check + save credentials
app.use(function(req, res, next) {
- req.
loggedIn = false;
- res.locals.user = { name: "" };
+ req.
userId = 0; //means "anonymous"
+ res.locals.user = { name: "" };
//"anonymous"
if (!req.cookies.token)
return next();
UserModel.getOne("sessionToken", req.cookies.token, function(err, user) {
if (!!user)
{
if (!req.cookies.token)
return next();
UserModel.getOne("sessionToken", req.cookies.token, function(err, user) {
if (!!user)
{
- req.
loggedIn = true
;
+ req.
userId = user.id
;
res.locals.user = {
res.locals.user = {
-
_id: user._
id,
+
id: user.
id,
name: user.name,
email: user.email,
notify: user.notify,
};
}
name: user.name,
email: user.email,
notify: user.notify,
};
}
+ else
+ {
+ // Token in cookies presumably wrong: erase it
+ res.clearCookie("token");
+ }
next();
});
});
next();
});
});