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/middlewares | |
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/middlewares')
-rw-r--r-- | server/middlewares/config.ts | 20 | ||||
-rw-r--r-- | server/middlewares/index.ts | 1 | ||||
-rw-r--r-- | server/middlewares/validators/users.ts | 15 |
3 files changed, 13 insertions, 23 deletions
diff --git a/server/middlewares/config.ts b/server/middlewares/config.ts deleted file mode 100644 index 1481e66cc..000000000 --- a/server/middlewares/config.ts +++ /dev/null | |||
@@ -1,20 +0,0 @@ | |||
1 | import 'express-validator' | ||
2 | import * as express from 'express' | ||
3 | |||
4 | import { CONFIG } from '../initializers' | ||
5 | |||
6 | function ensureUserRegistrationEnabled (req: express.Request, res: express.Response, next: express.NextFunction) { | ||
7 | const registrationEnabled = CONFIG.SIGNUP.ENABLED | ||
8 | |||
9 | if (registrationEnabled === true) { | ||
10 | return next() | ||
11 | } | ||
12 | |||
13 | return res.status(400).send('User registration is not enabled.') | ||
14 | } | ||
15 | |||
16 | // --------------------------------------------------------------------------- | ||
17 | |||
18 | export { | ||
19 | ensureUserRegistrationEnabled | ||
20 | } | ||
diff --git a/server/middlewares/index.ts b/server/middlewares/index.ts index 9a3f849a7..d71dd2452 100644 --- a/server/middlewares/index.ts +++ b/server/middlewares/index.ts | |||
@@ -1,6 +1,5 @@ | |||
1 | export * from './validators' | 1 | export * from './validators' |
2 | export * from './admin' | 2 | export * from './admin' |
3 | export * from './config' | ||
4 | export * from './oauth' | 3 | export * from './oauth' |
5 | export * from './pagination' | 4 | export * from './pagination' |
6 | export * from './pods' | 5 | export * from './pods' |
diff --git a/server/middlewares/validators/users.ts b/server/middlewares/validators/users.ts index 38f8aed5b..71e529872 100644 --- a/server/middlewares/validators/users.ts +++ b/server/middlewares/validators/users.ts | |||
@@ -5,7 +5,7 @@ import * as validator from 'validator' | |||
5 | 5 | ||
6 | import { database as db } from '../../initializers/database' | 6 | import { database as db } from '../../initializers/database' |
7 | import { checkErrors } from './utils' | 7 | import { checkErrors } from './utils' |
8 | import { logger } from '../../helpers' | 8 | import { isSignupAllowed, logger } from '../../helpers' |
9 | import { VideoInstance } from '../../models' | 9 | import { VideoInstance } from '../../models' |
10 | 10 | ||
11 | function usersAddValidator (req: express.Request, res: express.Response, next: express.NextFunction) { | 11 | function usersAddValidator (req: express.Request, res: express.Response, next: express.NextFunction) { |
@@ -88,11 +88,22 @@ function usersVideoRatingValidator (req: express.Request, res: express.Response, | |||
88 | }) | 88 | }) |
89 | } | 89 | } |
90 | 90 | ||
91 | function ensureUserRegistrationAllowed (req: express.Request, res: express.Response, next: express.NextFunction) { | ||
92 | isSignupAllowed().then(allowed => { | ||
93 | if (allowed === false) { | ||
94 | return res.status(403).send('User registration is not enabled or user limit is reached.') | ||
95 | } | ||
96 | |||
97 | return next() | ||
98 | }) | ||
99 | } | ||
100 | |||
91 | // --------------------------------------------------------------------------- | 101 | // --------------------------------------------------------------------------- |
92 | 102 | ||
93 | export { | 103 | export { |
94 | usersAddValidator, | 104 | usersAddValidator, |
95 | usersRemoveValidator, | 105 | usersRemoveValidator, |
96 | usersUpdateValidator, | 106 | usersUpdateValidator, |
97 | usersVideoRatingValidator | 107 | usersVideoRatingValidator, |
108 | ensureUserRegistrationAllowed | ||
98 | } | 109 | } |