Fix news notification system
[vchess.git] / server / routes / users.js
index 1196675..fc29730 100644 (file)
@@ -34,16 +34,23 @@ router.post('/register', access.unlogged, access.ajax, (req,res) => {
 });
 
 // NOTE: this method is safe because the sessionToken must be guessed
-router.get("/whoami", (req,res) => {
+router.get("/whoami", access.ajax, (req,res) => {
   const callback = (user) => {
     res.json({
       name: user.name,
       email: user.email,
       id: user.id,
       notify: user.notify,
+      newsRead: user.newsRead
     });
   };
-  const anonymous = {name:"", email:"", id:0, notify:false};
+  const anonymous = {
+    name: "",
+    email: "",
+    id: 0,
+    notify: false,
+    newsRead: 0
+  };
   if (!req.cookies.token)
     callback(anonymous);
   else if (req.cookies.token.match(/^[a-z0-9]+$/))
@@ -81,6 +88,12 @@ router.put('/update', access.logged, access.ajax, (req,res) => {
   }
 });
 
+// Special route to update newsRead timestamp:
+router.put('/newsread', access.logged, access.ajax, (req,res) => {
+  UserModel.setNewsRead(req.userId);
+  res.json({});
+});
+
 // Authentication-related methods:
 
 // to: object user (to who we send an email)
@@ -90,7 +103,7 @@ function setAndSendLoginToken(subject, to, res)
   const token = genToken(params.token.length);
   UserModel.setLoginToken(token, to.id);
   const body =
-    "Hello " + to.name + "!" + `
+    "Hello " + to.name + " !" + `
 ` +
     "Access your account here: " +
     params.siteURL + "/#/authenticate/" + token + `