diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-07-25 20:17:28 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-07-25 20:17:28 +0200 |
commit | 291e8d3eed88fe714fb74ad897ac2c67347a85ff (patch) | |
tree | 20b4f9b8500ab4d9651d2a067fcf2948a6bfc9a4 /server/helpers/utils.ts | |
parent | 3d09cdbf90902894c841d0a5ddb35eb772c53b8b (diff) | |
download | PeerTube-291e8d3eed88fe714fb74ad897ac2c67347a85ff.tar.gz PeerTube-291e8d3eed88fe714fb74ad897ac2c67347a85ff.tar.zst PeerTube-291e8d3eed88fe714fb74ad897ac2c67347a85ff.zip |
Add ability to limit user registrations
Diffstat (limited to 'server/helpers/utils.ts')
-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 | } |