X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=server%2Fmodels%2FUser.js;h=021cadcb32aebf0a3859d3da209b54c09245d011;hb=d9a7a1e40254bda6e545514596a7363048c084f9;hp=f3adb31d8b8401952c14323c3de5ea16b14d7de3;hpb=866842c3c310524c034922870234120ed2a16cbf;p=vchess.git diff --git a/server/models/User.js b/server/models/User.js index f3adb31d..021cadcb 100644 --- a/server/models/User.js +++ b/server/models/User.js @@ -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); }, @@ -141,13 +152,20 @@ const UserModel = const day = 86400000; db.serialize(function() { const query = - "SELECT id, sessionToken, created " + + "SELECT id, sessionToken, created, name, email " + "FROM Users"; db.all(query, (err, users) => { users.forEach(u => { - // Remove unlogged users for >1 day + // Remove unlogged users for > 24h if (!u.sessionToken && tsNow - u.created > day) + { + notify( + u, + "Your account has been deleted because " + + "you didn't log in for 24h after registration" + ); db.run("DELETE FROM Users WHERE id = " + u.id); + } }); }); });