From d14a9532a1363b464d6d15fce86afc4983a8357e Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 24 May 2018 15:30:28 +0200 Subject: Handle account name in client url More consistent with AP urls --- server/middlewares/validators/account.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'server/middlewares') diff --git a/server/middlewares/validators/account.ts b/server/middlewares/validators/account.ts index 0c4b7051d..c01e742da 100644 --- a/server/middlewares/validators/account.ts +++ b/server/middlewares/validators/account.ts @@ -2,13 +2,14 @@ import * as express from 'express' import { param } from 'express-validator/check' import { isAccountIdExist, + isAccountIdValid, isAccountNameValid, isAccountNameWithHostExist, isLocalAccountNameExist } from '../../helpers/custom-validators/accounts' -import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' import { logger } from '../../helpers/logger' import { areValidationErrors } from './utils' +import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' const localAccountValidator = [ param('name').custom(isAccountNameValid).withMessage('Should have a valid account name'), @@ -24,13 +25,18 @@ const localAccountValidator = [ ] const accountsGetValidator = [ - param('id').custom(isIdOrUUIDValid).withMessage('Should have a valid id'), + param('id').custom(isAccountIdValid).withMessage('Should have a valid id/uuid/name/name with host'), async (req: express.Request, res: express.Response, next: express.NextFunction) => { logger.debug('Checking accountsGetValidator parameters', { parameters: req.params }) if (areValidationErrors(req, res)) return - if (!await isAccountIdExist(req.params.id, res)) return + + let accountFetched = false + if (isIdOrUUIDValid(req.params.id)) accountFetched = await isAccountIdExist(req.params.id, res, false) + if (!accountFetched) accountFetched = await isAccountNameWithHostExist(req.params.id, res, true) + + if (!accountFetched) return return next() } -- cgit v1.2.3