1
0
Fork 0
peertube/server/middlewares/validators/account.ts

25 lines
838 B
TypeScript
Raw Normal View History

2017-11-09 16:51:58 +00:00
import * as express from 'express'
2017-11-13 16:39:41 +00:00
import { param } from 'express-validator/check'
2017-12-12 16:53:50 +00:00
import { isAccountNameValid, isLocalAccountNameExist } from '../../helpers/custom-validators/accounts'
2017-12-28 10:16:08 +00:00
import { logger } from '../../helpers/logger'
2017-11-27 16:30:46 +00:00
import { areValidationErrors } from './utils'
2017-11-09 16:51:58 +00:00
const localAccountValidator = [
2017-11-14 16:31:26 +00:00
param('name').custom(isAccountNameValid).withMessage('Should have a valid account name'),
2017-11-09 16:51:58 +00:00
2017-11-27 16:30:46 +00:00
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
2017-11-09 16:51:58 +00:00
logger.debug('Checking localAccountValidator parameters', { parameters: req.params })
2017-11-27 16:30:46 +00:00
if (areValidationErrors(req, res)) return
if (!await isLocalAccountNameExist(req.params.name, res)) return
return next()
2017-11-09 16:51:58 +00:00
}
]
// ---------------------------------------------------------------------------
export {
localAccountValidator
}