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:
parent
3d09cdbf90
commit
291e8d3eed
15 changed files with 97 additions and 41 deletions
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue