diff options
Diffstat (limited to 'server/helpers')
-rw-r--r-- | server/helpers/utils.ts | 20 |
1 files changed, 19 insertions, 1 deletions
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 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import * as Promise from 'bluebird' | ||
2 | 3 | ||
3 | import { pseudoRandomBytesPromise } from './core-utils' | 4 | import { pseudoRandomBytesPromise } from './core-utils' |
5 | import { CONFIG, database as db } from '../initializers' | ||
4 | import { ResultList } from '../../shared' | 6 | import { ResultList } from '../../shared' |
5 | 7 | ||
6 | function badRequest (req: express.Request, res: express.Response, next: express.NextFunction) { | 8 | function badRequest (req: express.Request, res: express.Response, next: express.NextFunction) { |
@@ -30,10 +32,26 @@ function getFormatedObjects<U, T extends FormatableToJSON> (objects: T[], object | |||
30 | return res | 32 | return res |
31 | } | 33 | } |
32 | 34 | ||
35 | function isSignupAllowed () { | ||
36 | if (CONFIG.SIGNUP.ENABLED === false) { | ||
37 | return Promise.resolve(false) | ||
38 | } | ||
39 | |||
40 | // No limit and signup is enabled | ||
41 | if (CONFIG.SIGNUP.LIMIT === -1) { | ||
42 | return Promise.resolve(true) | ||
43 | } | ||
44 | |||
45 | return db.User.countTotal().then(totalUsers => { | ||
46 | return totalUsers < CONFIG.SIGNUP.LIMIT | ||
47 | }) | ||
48 | } | ||
49 | |||
33 | // --------------------------------------------------------------------------- | 50 | // --------------------------------------------------------------------------- |
34 | 51 | ||
35 | export { | 52 | export { |
36 | badRequest, | 53 | badRequest, |
37 | generateRandomString, | 54 | generateRandomString, |
38 | getFormatedObjects | 55 | getFormatedObjects, |
56 | isSignupAllowed | ||
39 | } | 57 | } |