aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/utils.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-07-25 20:17:28 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-07-25 20:17:28 +0200
commit291e8d3eed88fe714fb74ad897ac2c67347a85ff (patch)
tree20b4f9b8500ab4d9651d2a067fcf2948a6bfc9a4 /server/helpers/utils.ts
parent3d09cdbf90902894c841d0a5ddb35eb772c53b8b (diff)
downloadPeerTube-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.ts20
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 @@
1import * as express from 'express' 1import * as express from 'express'
2import * as Promise from 'bluebird'
2 3
3import { pseudoRandomBytesPromise } from './core-utils' 4import { pseudoRandomBytesPromise } from './core-utils'
5import { CONFIG, database as db } from '../initializers'
4import { ResultList } from '../../shared' 6import { ResultList } from '../../shared'
5 7
6function badRequest (req: express.Request, res: express.Response, next: express.NextFunction) { 8function 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
35function 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
35export { 52export {
36 badRequest, 53 badRequest,
37 generateRandomString, 54 generateRandomString,
38 getFormatedObjects 55 getFormatedObjects,
56 isSignupAllowed
39} 57}