aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers/api')
-rw-r--r--server/controllers/api/users/index.ts25
1 files changed, 20 insertions, 5 deletions
diff --git a/server/controllers/api/users/index.ts b/server/controllers/api/users/index.ts
index 27351c1a9..b960e80c1 100644
--- a/server/controllers/api/users/index.ts
+++ b/server/controllers/api/users/index.ts
@@ -49,6 +49,7 @@ import { sequelizeTypescript } from '../../../initializers/database'
49import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model' 49import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model'
50import { UserRegister } from '../../../../shared/models/users/user-register.model' 50import { UserRegister } from '../../../../shared/models/users/user-register.model'
51import { MUser, MUserAccountDefault } from '@server/typings/models' 51import { MUser, MUserAccountDefault } from '@server/typings/models'
52import { Hooks } from '@server/lib/plugins/hooks'
52 53
53const auditLogger = auditLoggerFactory('users') 54const auditLogger = auditLoggerFactory('users')
54 55
@@ -172,7 +173,7 @@ usersRouter.post('/:id/verify-email',
172usersRouter.post('/token', 173usersRouter.post('/token',
173 loginRateLimiter, 174 loginRateLimiter,
174 token, 175 token,
175 success 176 tokenSuccess
176) 177)
177// TODO: Once https://github.com/oauthjs/node-oauth2-server/pull/289 is merged, implement revoke token route 178// TODO: Once https://github.com/oauthjs/node-oauth2-server/pull/289 is merged, implement revoke token route
178 179
@@ -198,11 +199,13 @@ async function createUser (req: express.Request, res: express.Response) {
198 adminFlags: body.adminFlags || UserAdminFlag.NONE 199 adminFlags: body.adminFlags || UserAdminFlag.NONE
199 }) as MUser 200 }) as MUser
200 201
201 const { user, account } = await createUserAccountAndChannelAndPlaylist({ userToCreate: userToCreate }) 202 const { user, account, videoChannel } = await createUserAccountAndChannelAndPlaylist({ userToCreate: userToCreate })
202 203
203 auditLogger.create(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON())) 204 auditLogger.create(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON()))
204 logger.info('User %s with its channel and account created.', body.username) 205 logger.info('User %s with its channel and account created.', body.username)
205 206
207 Hooks.runAction('action:api.user.created', { body, user, account, videoChannel })
208
206 return res.json({ 209 return res.json({
207 user: { 210 user: {
208 id: user.id, 211 id: user.id,
@@ -228,7 +231,7 @@ async function registerUser (req: express.Request, res: express.Response) {
228 emailVerified: CONFIG.SIGNUP.REQUIRES_EMAIL_VERIFICATION ? false : null 231 emailVerified: CONFIG.SIGNUP.REQUIRES_EMAIL_VERIFICATION ? false : null
229 }) 232 })
230 233
231 const { user } = await createUserAccountAndChannelAndPlaylist({ 234 const { user, account, videoChannel } = await createUserAccountAndChannelAndPlaylist({
232 userToCreate: userToCreate, 235 userToCreate: userToCreate,
233 userDisplayName: body.displayName || undefined, 236 userDisplayName: body.displayName || undefined,
234 channelNames: body.channel 237 channelNames: body.channel
@@ -243,6 +246,8 @@ async function registerUser (req: express.Request, res: express.Response) {
243 246
244 Notifier.Instance.notifyOnNewUserRegistration(user) 247 Notifier.Instance.notifyOnNewUserRegistration(user)
245 248
249 Hooks.runAction('action:api.user.registered', { body, user, account, videoChannel })
250
246 return res.type('json').status(204).end() 251 return res.type('json').status(204).end()
247} 252}
248 253
@@ -251,6 +256,8 @@ async function unblockUser (req: express.Request, res: express.Response) {
251 256
252 await changeUserBlock(res, user, false) 257 await changeUserBlock(res, user, false)
253 258
259 Hooks.runAction('action:api.user.unblocked', { user })
260
254 return res.status(204).end() 261 return res.status(204).end()
255} 262}
256 263
@@ -260,6 +267,8 @@ async function blockUser (req: express.Request, res: express.Response) {
260 267
261 await changeUserBlock(res, user, true, reason) 268 await changeUserBlock(res, user, true, reason)
262 269
270 Hooks.runAction('action:api.user.blocked', { user })
271
263 return res.status(204).end() 272 return res.status(204).end()
264} 273}
265 274
@@ -286,6 +295,8 @@ async function removeUser (req: express.Request, res: express.Response) {
286 295
287 auditLogger.delete(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON())) 296 auditLogger.delete(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON()))
288 297
298 Hooks.runAction('action:api.user.deleted', { user })
299
289 return res.sendStatus(204) 300 return res.sendStatus(204)
290} 301}
291 302
@@ -310,6 +321,8 @@ async function updateUser (req: express.Request, res: express.Response) {
310 321
311 auditLogger.update(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON()), oldUserAuditView) 322 auditLogger.update(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON()), oldUserAuditView)
312 323
324 Hooks.runAction('action:api.user.updated', { user })
325
313 // Don't need to send this update to followers, these attributes are not federated 326 // Don't need to send this update to followers, these attributes are not federated
314 327
315 return res.sendStatus(204) 328 return res.sendStatus(204)
@@ -356,8 +369,10 @@ async function verifyUserEmail (req: express.Request, res: express.Response) {
356 return res.status(204).end() 369 return res.status(204).end()
357} 370}
358 371
359function success (req: express.Request, res: express.Response) { 372function tokenSuccess (req: express.Request) {
360 res.end() 373 const username = req.body.username
374
375 Hooks.runAction('action:api.user.oauth2-got-token', { username, ip: req.ip })
361} 376}
362 377
363async function changeUserBlock (res: express.Response, user: MUserAccountDefault, block: boolean, reason?: string) { 378async function changeUserBlock (res: express.Response, user: MUserAccountDefault, block: boolean, reason?: string) {