X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=server%2Fmodels%2FUser.js;h=7a0f70a78ca30cdd00af2d6eb4654d703532d704;hb=5d04793e1bce0d448b4ffc532f1e8eb47a72e972;hp=a36ab683487fd7d9d6bc8761ee105536e0c9ca42;hpb=625022fdcf750f0aff8fcd699f7e9b89730e1d10;p=vchess.git diff --git a/server/models/User.js b/server/models/User.js index a36ab683..7a0f70a7 100644 --- a/server/models/User.js +++ b/server/models/User.js @@ -16,6 +16,24 @@ var params = require("../config/parameters"); const UserModel = { + checkNameEmail: function(o) + { + if (typeof o.name === "string") + { + if (o.name.length == 0) + return "Empty name"; + if (!o.name.match(/^[\w]+$/)) + return "Bad characters in name"; + } + if (typeof o.email === "string") + { + if (o.email.length == 0) + return "Empty email"; + if (!o.email.match(/^[\w.+-]+@[\w.+-]+$/)) + return "Bad characters in email"; + } + }, + // NOTE: parameters are already cleaned (in controller), thus no sanitization here create: function(name, email, notify, callback) { @@ -45,6 +63,16 @@ const UserModel = }); }, + getByName: function(names, cb) { + db.serialize(function() { + const query = + "SELECT id " + + "FROM Users " + + "WHERE name IN ('" + names.join("','") + "')"; + db.all(query, cb); + }); + }, + ///////// // MODIFY @@ -96,6 +124,15 @@ const UserModel = db.run(query, cb); }); }, + + ///////////////// + // NOTIFICATIONS + + tryNotify: function(oppId, gid, vname, message) + { + // TODO: send email to oppId (request...) with title + // "vchess.club - vname" and content "message" + } } module.exports = UserModel;