Experimental news notification system + fix Eightpieces variant
[vchess.git] / server / models / User.js
index 3b88850..021cadc 100644 (file)
@@ -20,8 +20,8 @@ const UserModel =
   checkNameEmail: function(o)
   {
     return (
-      (!o.name || o.name.match(/^[\w-]+$/)) &&
-      (!o.email || o.email.match(/^[\w.+-]+@[\w.+-]+$/))
+      (!o.name || !!(o.name.match(/^[\w-]+$/))) &&
+      (!o.email || !!(o.email.match(/^[\w.+-]+@[\w.+-]+$/)))
     );
   },
 
@@ -75,6 +75,17 @@ const UserModel =
     });
   },
 
+  setNewsRead: function(uid)
+  {
+    db.serialize(function() {
+      const query =
+        "UPDATE Users " +
+        "SET newsRead = " + Date.now() + " " +
+        "WHERE id = " + uid;
+      db.run(query);
+    });
+  },
+
   // Set session token only if empty (first login)
   // NOTE: weaker security (but avoid to re-login everywhere after each logout)
   // TODO: option would be to reset all tokens periodically, e.g. every 3 months
@@ -118,7 +129,7 @@ const UserModel =
   notify: function(user, message)
   {
     const subject = "vchess.club - notification";
-    const body = "Hello " + user.name + "!" + `
+    const body = "Hello " + user.name + " !" + `
 ` + message;
     sendEmail(params.mail.noreply, user.email, subject, body);
   },