X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmiddlewares%2Fvalidators%2Fusers.ts;h=8ca9763a1ddf6b164aae734bc0f567728a0c6367;hb=0b18f4aa80df8868bf34605423c7a298dffbb2aa;hp=247b704c4331d8ff27c397220ec41de20d90303f;hpb=ed56ad1193bb5bb0a81fb843a11eb90d3fed9861;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/middlewares/validators/users.ts b/server/middlewares/validators/users.ts index 247b704c4..8ca9763a1 100644 --- a/server/middlewares/validators/users.ts +++ b/server/middlewares/validators/users.ts @@ -5,9 +5,9 @@ import { body, param } from 'express-validator/check' import { omit } from 'lodash' import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' import { - isAvatarFile, isUserAutoPlayVideoValid, - isUserDescriptionValid, isUserDisplayNameValid, + isUserDescriptionValid, + isUserDisplayNameValid, isUserNSFWPolicyValid, isUserPasswordValid, isUserRoleValid, @@ -16,11 +16,11 @@ import { } from '../../helpers/custom-validators/users' import { isVideoExist } from '../../helpers/custom-validators/videos' import { logger } from '../../helpers/logger' -import { isSignupAllowed } from '../../helpers/utils' -import { CONSTRAINTS_FIELDS } from '../../initializers' +import { isSignupAllowed, isSignupAllowedForCurrentIP } from '../../helpers/utils' import { Redis } from '../../lib/redis' import { UserModel } from '../../models/account/user' import { areValidationErrors } from './utils' +import { ActorModel } from '../../models/activitypub/actor' const usersAddValidator = [ body('username').custom(isUserUsernameValid).withMessage('Should have a valid username (lowercase alphanumeric characters)'), @@ -115,29 +115,6 @@ const usersUpdateMeValidator = [ } ] -const usersUpdateMyAvatarValidator = [ - body('avatarfile').custom((value, { req }) => isAvatarFile(req.files)).withMessage( - 'This file is not supported. Please, make sure it is of the following type : ' - + CONSTRAINTS_FIELDS.ACTORS.AVATAR.EXTNAME.join(', ') - ), - - (req: express.Request, res: express.Response, next: express.NextFunction) => { - logger.debug('Checking usersUpdateMyAvatarValidator parameters', { files: req.files }) - - if (areValidationErrors(req, res)) return - - const imageFile = req.files['avatarfile'][0] as Express.Multer.File - if (imageFile.size > CONSTRAINTS_FIELDS.ACTORS.AVATAR.FILE_SIZE.max) { - res.status(400) - .send({ error: `The size of the avatar is too big (>${CONSTRAINTS_FIELDS.ACTORS.AVATAR.FILE_SIZE.max}).` }) - .end() - return - } - - return next() - } -] - const usersGetValidator = [ param('id').isInt().not().isEmpty().withMessage('Should have a valid id'), @@ -177,6 +154,20 @@ const ensureUserRegistrationAllowed = [ } ] +const ensureUserRegistrationAllowedForIP = [ + async (req: express.Request, res: express.Response, next: express.NextFunction) => { + const allowed = isSignupAllowedForCurrentIP(req.ip) + + if (allowed === false) { + return res.status(403) + .send({ error: 'You are not on a network authorized for registration.' }) + .end() + } + + return next() + } +] + const usersAskResetPasswordValidator = [ body('email').isEmail().not().isEmpty().withMessage('Should have a valid email'), @@ -230,8 +221,8 @@ export { usersUpdateMeValidator, usersVideoRatingValidator, ensureUserRegistrationAllowed, + ensureUserRegistrationAllowedForIP, usersGetValidator, - usersUpdateMyAvatarValidator, usersAskResetPasswordValidator, usersResetPasswordValidator } @@ -256,6 +247,14 @@ async function checkUserNameOrEmailDoesNotAlreadyExist (username: string, email: return false } + const actor = await ActorModel.loadLocalByName(username) + if (actor) { + res.status(409) + .send({ error: 'Another actor (account/channel) with this name already exists.' }) + .end() + return false + } + return true }