const name = req.body.name;
const email = req.body.email;
const notify = !!req.body.notify;
const name = req.body.name;
const email = req.body.email;
const notify = !!req.body.notify;
UserModel.create(name, email, notify, (err, ret) => {
if (!!err) {
const msg = err.code == "SQLITE_CONSTRAINT"
? "User name or email already in use"
: "User creation failed. Try again";
UserModel.create(name, email, notify, (err, ret) => {
if (!!err) {
const msg = err.code == "SQLITE_CONSTRAINT"
? "User name or email already in use"
: "User creation failed. Try again";
// NOTE: slightly too permissive RegExp
if (ids.match(/^([0-9]+,?)+$/)) {
UserModel.getByIds(ids, (err, users) => {
// NOTE: slightly too permissive RegExp
if (ids.match(/^([0-9]+,?)+$/)) {
UserModel.getByIds(ids, (err, users) => {
router.put('/update', access.logged, access.ajax, (req,res) => {
const name = req.body.name;
const email = req.body.email;
router.put('/update', access.logged, access.ajax, (req,res) => {
const name = req.body.name;
const email = req.body.email;
router.get('/sendtoken', access.unlogged, access.ajax, (req,res) => {
const nameOrEmail = decodeURIComponent(req.query.nameOrEmail);
const type = (nameOrEmail.indexOf('@') >= 0 ? "email" : "name");
router.get('/sendtoken', access.unlogged, access.ajax, (req,res) => {
const nameOrEmail = decodeURIComponent(req.query.nameOrEmail);
const type = (nameOrEmail.indexOf('@') >= 0 ? "email" : "name");
UserModel.getOne(type, nameOrEmail, (err,user) => {
access.checkRequest(res, err, user, "Unknown user", () => {
setAndSendLoginToken("Token for " + params.siteURL, user, res);
UserModel.getOne(type, nameOrEmail, (err,user) => {
access.checkRequest(res, err, user, "Unknown user", () => {
setAndSendLoginToken("Token for " + params.siteURL, user, res);
router.get('/authenticate', access.unlogged, access.ajax, (req,res) => {
if (!req.query.token.match(/^[a-z0-9]+$/))
router.get('/authenticate', access.unlogged, access.ajax, (req,res) => {
if (!req.query.token.match(/^[a-z0-9]+$/))
UserModel.getOne("loginToken", req.query.token, (err,user) => {
access.checkRequest(res, err, user, "Invalid token", () => {
// If token older than params.tokenExpire, do nothing
if (Date.now() > user.loginTime + params.token.expire)
UserModel.getOne("loginToken", req.query.token, (err,user) => {
access.checkRequest(res, err, user, "Invalid token", () => {
// If token older than params.tokenExpire, do nothing
if (Date.now() > user.loginTime + params.token.expire)
else {
// Generate session token (if not exists) + destroy login token
UserModel.trySetSessionToken(user.id, (token) => {
else {
// Generate session token (if not exists) + destroy login token
UserModel.trySetSessionToken(user.id, (token) => {