1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-03 17:59:37 +02:00

Add ability to limit user registrations

This commit is contained in:
Chocobozzz 2017-07-25 20:17:28 +02:00
parent 3d09cdbf90
commit 291e8d3eed
15 changed files with 97 additions and 41 deletions

View file

@ -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<U, T extends FormatableToJSON> (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
}