From 0aa79c55c471b6a816723b021b3b50c9f6b0dec6 Mon Sep 17 00:00:00 2001
From: Benjamin Auder <benjamin.auder@somewhere>
Date: Fri, 11 Dec 2020 15:16:57 +0100
Subject: [PATCH] Update tournament DB at each user registration

---
 server/config/parameters.js.dist | 5 ++++-
 server/routes/users.js           | 3 +++
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/server/config/parameters.js.dist b/server/config/parameters.js.dist
index 9ba76182..b7abc139 100644
--- a/server/config/parameters.js.dist
+++ b/server/config/parameters.js.dist
@@ -5,7 +5,7 @@ module.exports = {
 
   // To know in which environment the code run
   env: process.env.NODE_ENV || 'development',
-  
+
   // CORS: cross-origin resource sharing options
   cors: {
     enable: true,
@@ -21,6 +21,9 @@ module.exports = {
     expire: 30*60*1000, //30 minutes in milliseconds
   },
 
+  // Path to tournament repository (to synchronize DBs)
+  tourneyPath: "/path/to/folder",
+
   // Email settings
   mail: {
     host: "mail_host_address",
diff --git a/server/routes/users.js b/server/routes/users.js
index 51c3063e..21585c7c 100644
--- a/server/routes/users.js
+++ b/server/routes/users.js
@@ -5,6 +5,7 @@ const genToken = require("../utils/tokenGenerator");
 const access = require("../utils/access");
 const params = require("../config/parameters");
 const sanitizeHtml_pkg = require('sanitize-html');
+const { exec } = require("child_process");
 
 const allowedTags = [
   'h3', 'h4', 'h5', 'h6', 'blockquote', 'p', 'a', 'ul', 'ol', 'li', 'b',
@@ -49,6 +50,8 @@ router.post('/register', access.unlogged, access.ajax, (req,res) => {
           email: email
         };
         setAndSendLoginToken("Welcome to " + params.siteURL, user);
+        // Update tournament DB (TODO: if error, log it)
+        exec(params.tourneyPath + "/sync_users.py");
         res.json({});
       }
     });
-- 
2.48.1