- UserModel.getOne("id", oppId, (err,opp) => {
- if (!err || !opp.notify)
- return; //error is ignored here (TODO: should be logged)
- const subject = "vchess.club - notification";
- const body = "Hello " + opp.name + "!\n" + message;
- sendEmail(params.mail.noreply, opp.email, subject, body, err => {
- res.json(err || {});
+ const subject = "vchess.club - notification";
+ const body = "Hello " + user.name + "!" + `
+` + message;
+ sendEmail(params.mail.noreply, user.email, subject, body);
+ },
+
+ tryNotify: function(id, message)
+ {
+ UserModel.getOne("id", id, (err,user) => {
+ if (!err && user.notify)
+ UserModel.notify(user, message);
+ });
+ },
+
+ ////////////
+ // CLEANING
+
+ cleanUsersDb: function()
+ {
+ const tsNow = Date.now();
+ // 86400000 = 24 hours in milliseconds
+ const day = 86400000;
+ db.serialize(function() {
+ const query =
+ "SELECT id, sessionToken, created, name, email " +
+ "FROM Users";
+ db.all(query, (err, users) => {
+ users.forEach(u => {
+ // 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);
+ }
+ });