From 827f6399e94687ad03d73b17a7ed8f3cf2154c45 Mon Sep 17 00:00:00 2001 From: xfarrow Date: Mon, 16 Oct 2023 14:59:46 +0200 Subject: [PATCH] Allow/deny users to register --- backend/apis/nodejs/.env | 2 +- backend/apis/nodejs/api_controller.js | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/backend/apis/nodejs/.env b/backend/apis/nodejs/.env index 3b080b9..3f3d8b6 100644 --- a/backend/apis/nodejs/.env +++ b/backend/apis/nodejs/.env @@ -10,4 +10,4 @@ POSTGRES_PASSWORD = postgres POSTGRES_PORT = 5432 # Application settings -ALLOW_USER_REGISTRATION = true \ No newline at end of file +ALLOW_USER_REGISTRATION = false \ No newline at end of file diff --git a/backend/apis/nodejs/api_controller.js b/backend/apis/nodejs/api_controller.js index 5f8f659..1f2d260 100644 --- a/backend/apis/nodejs/api_controller.js +++ b/backend/apis/nodejs/api_controller.js @@ -31,6 +31,10 @@ const jwt = require('jsonwebtoken'); // POST async function registerPerson(req, res){ + if (process.env.ALLOW_USER_REGISTRATION === 'false'){ + return res.status(403).json({error : "Users cannot register on this server"}); + } + // Ensure that the required fields are present before proceeding if (!req.body.display_name || !req.body.email || !req.body.password) { return res.status(400).json("Invalid request."); @@ -54,7 +58,8 @@ async function registerPerson(req, res){ date_of_birth: req.body.date_of_birth, available: req.body.available, enabled: true, - place_of_living: req.body.place_of_living}) + place_of_living: req.body.place_of_living + }) .returning("id"); await tr('ActivationLink')