aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators/users.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-09-14 17:06:31 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-09-14 17:25:36 +0200
commitbfb3a98fac582f104c6d9b8b7242ea2cbb650b91 (patch)
tree24ead7cbbdc785315c406dfba85a55fe5e235d09 /server/middlewares/validators/users.ts
parentd5050d1e097e761685fbaafe6e3d4b8b78d48356 (diff)
downloadPeerTube-bfb3a98fac582f104c6d9b8b7242ea2cbb650b91.tar.gz
PeerTube-bfb3a98fac582f104c6d9b8b7242ea2cbb650b91.tar.zst
PeerTube-bfb3a98fac582f104c6d9b8b7242ea2cbb650b91.zip
Remove ng2 file upload module
Unmaintained and we don't need it anymore with httpclient
Diffstat (limited to 'server/middlewares/validators/users.ts')
-rw-r--r--server/middlewares/validators/users.ts36
1 files changed, 27 insertions, 9 deletions
diff --git a/server/middlewares/validators/users.ts b/server/middlewares/validators/users.ts
index aec6324bf..15c07c693 100644
--- a/server/middlewares/validators/users.ts
+++ b/server/middlewares/validators/users.ts
@@ -45,9 +45,13 @@ function usersRemoveValidator (req: express.Request, res: express.Response, next
45 return res.sendStatus(500) 45 return res.sendStatus(500)
46 } 46 }
47 47
48 if (user.username === 'root') return res.status(400).send('Cannot remove the root user') 48 if (user.username === 'root') {
49 return res.status(400)
50 .send({ error: 'Cannot remove the root user' })
51 .end()
52 }
49 53
50 next() 54 return next()
51 }) 55 })
52 }) 56 })
53} 57}
@@ -99,9 +103,13 @@ function usersVideoRatingValidator (req: express.Request, res: express.Response,
99 103
100 videoPromise 104 videoPromise
101 .then(video => { 105 .then(video => {
102 if (!video) return res.status(404).send('Video not found') 106 if (!video) {
107 return res.status(404)
108 .json({ error: 'Video not found' })
109 .end()
110 }
103 111
104 next() 112 return next()
105 }) 113 })
106 .catch(err => { 114 .catch(err => {
107 logger.error('Error in user request validator.', err) 115 logger.error('Error in user request validator.', err)
@@ -113,7 +121,9 @@ function usersVideoRatingValidator (req: express.Request, res: express.Response,
113function ensureUserRegistrationAllowed (req: express.Request, res: express.Response, next: express.NextFunction) { 121function ensureUserRegistrationAllowed (req: express.Request, res: express.Response, next: express.NextFunction) {
114 isSignupAllowed().then(allowed => { 122 isSignupAllowed().then(allowed => {
115 if (allowed === false) { 123 if (allowed === false) {
116 return res.status(403).send('User registration is not enabled or user limit is reached.') 124 return res.status(403)
125 .send({ error: 'User registration is not enabled or user limit is reached.' })
126 .end()
117 } 127 }
118 128
119 return next() 129 return next()
@@ -138,10 +148,14 @@ export {
138function checkUserExists (id: number, res: express.Response, callback: (err: Error, user: UserInstance) => void) { 148function checkUserExists (id: number, res: express.Response, callback: (err: Error, user: UserInstance) => void) {
139 db.User.loadById(id) 149 db.User.loadById(id)
140 .then(user => { 150 .then(user => {
141 if (!user) return res.status(404).send('User not found') 151 if (!user) {
152 return res.status(404)
153 .send({ error: 'User not found' })
154 .end()
155 }
142 156
143 res.locals.user = user 157 res.locals.user = user
144 callback(null, user) 158 return callback(null, user)
145 }) 159 })
146 .catch(err => { 160 .catch(err => {
147 logger.error('Error in user request validator.', err) 161 logger.error('Error in user request validator.', err)
@@ -152,9 +166,13 @@ function checkUserExists (id: number, res: express.Response, callback: (err: Err
152function checkUserDoesNotAlreadyExist (username: string, email: string, res: express.Response, callback: () => void) { 166function checkUserDoesNotAlreadyExist (username: string, email: string, res: express.Response, callback: () => void) {
153 db.User.loadByUsernameOrEmail(username, email) 167 db.User.loadByUsernameOrEmail(username, email)
154 .then(user => { 168 .then(user => {
155 if (user) return res.status(409).send('User already exists.') 169 if (user) {
170 return res.status(409)
171 .send({ error: 'User already exists.' })
172 .end()
173 }
156 174
157 callback() 175 return callback()
158 }) 176 })
159 .catch(err => { 177 .catch(err => {
160 logger.error('Error in usersAdd request validator.', err) 178 logger.error('Error in usersAdd request validator.', err)