X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=server%2Fmodels%2FUser.js;h=9b3049bebd0ab6ac4ff916bbe9b65a58122d28be;hb=f53871dbb29b5f7f4dd8d72e76387ad8f1d7863b;hp=f3adb31d8b8401952c14323c3de5ea16b14d7de3;hpb=866842c3c310524c034922870234120ed2a16cbf;p=vchess.git diff --git a/server/models/User.js b/server/models/User.js index f3adb31d..9b3049be 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.+-]+$/))) ); }, @@ -118,7 +118,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 +141,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); + } }); }); });