]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/middlewares/validators/users.ts
Add advanced search in client
[github/Chocobozzz/PeerTube.git] / server / middlewares / validators / users.ts
index 4ad0e33da7d203d2d9eedad64d512370b917e81c..8ca9763a1ddf6b164aae734bc0f567728a0c6367 100644 (file)
@@ -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,
@@ -17,10 +17,10 @@ import {
 import { isVideoExist } from '../../helpers/custom-validators/videos'
 import { logger } from '../../helpers/logger'
 import { isSignupAllowed, isSignupAllowedForCurrentIP } from '../../helpers/utils'
-import { CONFIG, CONSTRAINTS_FIELDS } from '../../initializers'
 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'),
 
@@ -246,7 +223,6 @@ export {
   ensureUserRegistrationAllowed,
   ensureUserRegistrationAllowedForIP,
   usersGetValidator,
-  usersUpdateMyAvatarValidator,
   usersAskResetPasswordValidator,
   usersResetPasswordValidator
 }
@@ -271,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
 }