aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators/account.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-11-09 17:51:58 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-11-27 19:40:51 +0100
commite4f97babf701481b55cc10fb3448feab5f97c867 (patch)
treeaf37402a594dc5ff09f71ecb0687e8cfe4cdb471 /server/middlewares/validators/account.ts
parent343ad675f2a26c15b86150a9a3552e619d5d44f4 (diff)
downloadPeerTube-e4f97babf701481b55cc10fb3448feab5f97c867.tar.gz
PeerTube-e4f97babf701481b55cc10fb3448feab5f97c867.tar.zst
PeerTube-e4f97babf701481b55cc10fb3448feab5f97c867.zip
Begin activitypub
Diffstat (limited to 'server/middlewares/validators/account.ts')
-rw-r--r--server/middlewares/validators/account.ts53
1 files changed, 53 insertions, 0 deletions
diff --git a/server/middlewares/validators/account.ts b/server/middlewares/validators/account.ts
new file mode 100644
index 000000000..5abe942d6
--- /dev/null
+++ b/server/middlewares/validators/account.ts
@@ -0,0 +1,53 @@
1import { param } from 'express-validator/check'
2import * as express from 'express'
3
4import { database as db } from '../../initializers/database'
5import { checkErrors } from './utils'
6import {
7 logger,
8 isUserUsernameValid,
9 isUserPasswordValid,
10 isUserVideoQuotaValid,
11 isUserDisplayNSFWValid,
12 isUserRoleValid,
13 isAccountNameValid
14} from '../../helpers'
15import { AccountInstance } from '../../models'
16
17const localAccountValidator = [
18 param('name').custom(isAccountNameValid).withMessage('Should have a valid account name'),
19
20 (req: express.Request, res: express.Response, next: express.NextFunction) => {
21 logger.debug('Checking localAccountValidator parameters', { parameters: req.params })
22
23 checkErrors(req, res, () => {
24 checkLocalAccountExists(req.params.name, res, next)
25 })
26 }
27]
28
29// ---------------------------------------------------------------------------
30
31export {
32 localAccountValidator
33}
34
35// ---------------------------------------------------------------------------
36
37function checkLocalAccountExists (name: string, res: express.Response, callback: (err: Error, account: AccountInstance) => void) {
38 db.Account.loadLocalAccountByName(name)
39 .then(account => {
40 if (!account) {
41 return res.status(404)
42 .send({ error: 'Account not found' })
43 .end()
44 }
45
46 res.locals.account = account
47 return callback(null, account)
48 })
49 .catch(err => {
50 logger.error('Error in account request validator.', err)
51 return res.sendStatus(500)
52 })
53}