From 291e8d3eed88fe714fb74ad897ac2c67347a85ff Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 25 Jul 2017 20:17:28 +0200 Subject: Add ability to limit user registrations --- server/helpers/utils.ts | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'server/helpers') diff --git a/server/helpers/utils.ts b/server/helpers/utils.ts index 9c08afb71..f326210f3 100644 --- a/server/helpers/utils.ts +++ b/server/helpers/utils.ts @@ -1,6 +1,8 @@ import * as express from 'express' +import * as Promise from 'bluebird' import { pseudoRandomBytesPromise } from './core-utils' +import { CONFIG, database as db } from '../initializers' import { ResultList } from '../../shared' function badRequest (req: express.Request, res: express.Response, next: express.NextFunction) { @@ -30,10 +32,26 @@ function getFormatedObjects (objects: T[], object return res } +function isSignupAllowed () { + if (CONFIG.SIGNUP.ENABLED === false) { + return Promise.resolve(false) + } + + // No limit and signup is enabled + if (CONFIG.SIGNUP.LIMIT === -1) { + return Promise.resolve(true) + } + + return db.User.countTotal().then(totalUsers => { + return totalUsers < CONFIG.SIGNUP.LIMIT + }) +} + // --------------------------------------------------------------------------- export { badRequest, generateRandomString, - getFormatedObjects + getFormatedObjects, + isSignupAllowed } -- cgit v1.2.3