diff options
Diffstat (limited to 'server/controllers/api/users/index.ts')
-rw-r--r-- | server/controllers/api/users/index.ts | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/server/controllers/api/users/index.ts b/server/controllers/api/users/index.ts index 0b0081520..e3533a7f6 100644 --- a/server/controllers/api/users/index.ts +++ b/server/controllers/api/users/index.ts | |||
@@ -37,6 +37,11 @@ import { UserModel } from '../../../models/account/user' | |||
37 | import { auditLoggerFactory, getAuditIdFromRes, UserAuditView } from '../../../helpers/audit-logger' | 37 | import { auditLoggerFactory, getAuditIdFromRes, UserAuditView } from '../../../helpers/audit-logger' |
38 | import { meRouter } from './me' | 38 | import { meRouter } from './me' |
39 | import { deleteUserToken } from '../../../lib/oauth-model' | 39 | import { deleteUserToken } from '../../../lib/oauth-model' |
40 | import { myBlocklistRouter } from './my-blocklist' | ||
41 | import { myVideosHistoryRouter } from './my-history' | ||
42 | import { myNotificationsRouter } from './my-notifications' | ||
43 | import { Notifier } from '../../../lib/notifier' | ||
44 | import { mySubscriptionsRouter } from './my-subscriptions' | ||
40 | 45 | ||
41 | const auditLogger = auditLoggerFactory('users') | 46 | const auditLogger = auditLoggerFactory('users') |
42 | 47 | ||
@@ -53,6 +58,10 @@ const askSendEmailLimiter = new RateLimit({ | |||
53 | }) | 58 | }) |
54 | 59 | ||
55 | const usersRouter = express.Router() | 60 | const usersRouter = express.Router() |
61 | usersRouter.use('/', myNotificationsRouter) | ||
62 | usersRouter.use('/', mySubscriptionsRouter) | ||
63 | usersRouter.use('/', myBlocklistRouter) | ||
64 | usersRouter.use('/', myVideosHistoryRouter) | ||
56 | usersRouter.use('/', meRouter) | 65 | usersRouter.use('/', meRouter) |
57 | 66 | ||
58 | usersRouter.get('/autocomplete', | 67 | usersRouter.get('/autocomplete', |
@@ -207,6 +216,8 @@ async function registerUser (req: express.Request, res: express.Response) { | |||
207 | await sendVerifyUserEmail(user) | 216 | await sendVerifyUserEmail(user) |
208 | } | 217 | } |
209 | 218 | ||
219 | Notifier.Instance.notifyOnNewUserRegistration(user) | ||
220 | |||
210 | return res.type('json').status(204).end() | 221 | return res.type('json').status(204).end() |
211 | } | 222 | } |
212 | 223 | ||
@@ -218,7 +229,7 @@ async function unblockUser (req: express.Request, res: express.Response, next: e | |||
218 | return res.status(204).end() | 229 | return res.status(204).end() |
219 | } | 230 | } |
220 | 231 | ||
221 | async function blockUser (req: express.Request, res: express.Response, next: express.NextFunction) { | 232 | async function blockUser (req: express.Request, res: express.Response) { |
222 | const user: UserModel = res.locals.user | 233 | const user: UserModel = res.locals.user |
223 | const reason = req.body.reason | 234 | const reason = req.body.reason |
224 | 235 | ||
@@ -227,23 +238,23 @@ async function blockUser (req: express.Request, res: express.Response, next: exp | |||
227 | return res.status(204).end() | 238 | return res.status(204).end() |
228 | } | 239 | } |
229 | 240 | ||
230 | function getUser (req: express.Request, res: express.Response, next: express.NextFunction) { | 241 | function getUser (req: express.Request, res: express.Response) { |
231 | return res.json((res.locals.user as UserModel).toFormattedJSON()) | 242 | return res.json((res.locals.user as UserModel).toFormattedJSON()) |
232 | } | 243 | } |
233 | 244 | ||
234 | async function autocompleteUsers (req: express.Request, res: express.Response, next: express.NextFunction) { | 245 | async function autocompleteUsers (req: express.Request, res: express.Response) { |
235 | const resultList = await UserModel.autoComplete(req.query.search as string) | 246 | const resultList = await UserModel.autoComplete(req.query.search as string) |
236 | 247 | ||
237 | return res.json(resultList) | 248 | return res.json(resultList) |
238 | } | 249 | } |
239 | 250 | ||
240 | async function listUsers (req: express.Request, res: express.Response, next: express.NextFunction) { | 251 | async function listUsers (req: express.Request, res: express.Response) { |
241 | const resultList = await UserModel.listForApi(req.query.start, req.query.count, req.query.sort) | 252 | const resultList = await UserModel.listForApi(req.query.start, req.query.count, req.query.sort, req.query.search) |
242 | 253 | ||
243 | return res.json(getFormattedObjects(resultList.data, resultList.total)) | 254 | return res.json(getFormattedObjects(resultList.data, resultList.total)) |
244 | } | 255 | } |
245 | 256 | ||
246 | async function removeUser (req: express.Request, res: express.Response, next: express.NextFunction) { | 257 | async function removeUser (req: express.Request, res: express.Response) { |
247 | const user: UserModel = res.locals.user | 258 | const user: UserModel = res.locals.user |
248 | 259 | ||
249 | await user.destroy() | 260 | await user.destroy() |
@@ -253,13 +264,15 @@ async function removeUser (req: express.Request, res: express.Response, next: ex | |||
253 | return res.sendStatus(204) | 264 | return res.sendStatus(204) |
254 | } | 265 | } |
255 | 266 | ||
256 | async function updateUser (req: express.Request, res: express.Response, next: express.NextFunction) { | 267 | async function updateUser (req: express.Request, res: express.Response) { |
257 | const body: UserUpdate = req.body | 268 | const body: UserUpdate = req.body |
258 | const userToUpdate = res.locals.user as UserModel | 269 | const userToUpdate = res.locals.user as UserModel |
259 | const oldUserAuditView = new UserAuditView(userToUpdate.toFormattedJSON()) | 270 | const oldUserAuditView = new UserAuditView(userToUpdate.toFormattedJSON()) |
260 | const roleChanged = body.role !== undefined && body.role !== userToUpdate.role | 271 | const roleChanged = body.role !== undefined && body.role !== userToUpdate.role |
261 | 272 | ||
273 | if (body.password !== undefined) userToUpdate.password = body.password | ||
262 | if (body.email !== undefined) userToUpdate.email = body.email | 274 | if (body.email !== undefined) userToUpdate.email = body.email |
275 | if (body.emailVerified !== undefined) userToUpdate.emailVerified = body.emailVerified | ||
263 | if (body.videoQuota !== undefined) userToUpdate.videoQuota = body.videoQuota | 276 | if (body.videoQuota !== undefined) userToUpdate.videoQuota = body.videoQuota |
264 | if (body.videoQuotaDaily !== undefined) userToUpdate.videoQuotaDaily = body.videoQuotaDaily | 277 | if (body.videoQuotaDaily !== undefined) userToUpdate.videoQuotaDaily = body.videoQuotaDaily |
265 | if (body.role !== undefined) userToUpdate.role = body.role | 278 | if (body.role !== undefined) userToUpdate.role = body.role |
@@ -267,11 +280,11 @@ async function updateUser (req: express.Request, res: express.Response, next: ex | |||
267 | const user = await userToUpdate.save() | 280 | const user = await userToUpdate.save() |
268 | 281 | ||
269 | // Destroy user token to refresh rights | 282 | // Destroy user token to refresh rights |
270 | if (roleChanged) await deleteUserToken(userToUpdate.id) | 283 | if (roleChanged || body.password !== undefined) await deleteUserToken(userToUpdate.id) |
271 | 284 | ||
272 | auditLogger.update(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON()), oldUserAuditView) | 285 | auditLogger.update(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON()), oldUserAuditView) |
273 | 286 | ||
274 | // Don't need to send this update to followers, these attributes are not propagated | 287 | // Don't need to send this update to followers, these attributes are not federated |
275 | 288 | ||
276 | return res.sendStatus(204) | 289 | return res.sendStatus(204) |
277 | } | 290 | } |
@@ -281,7 +294,7 @@ async function askResetUserPassword (req: express.Request, res: express.Response | |||
281 | 294 | ||
282 | const verificationString = await Redis.Instance.setResetPasswordVerificationString(user.id) | 295 | const verificationString = await Redis.Instance.setResetPasswordVerificationString(user.id) |
283 | const url = CONFIG.WEBSERVER.URL + '/reset-password?userId=' + user.id + '&verificationString=' + verificationString | 296 | const url = CONFIG.WEBSERVER.URL + '/reset-password?userId=' + user.id + '&verificationString=' + verificationString |
284 | await Emailer.Instance.addForgetPasswordEmailJob(user.email, url) | 297 | await Emailer.Instance.addPasswordResetEmailJob(user.email, url) |
285 | 298 | ||
286 | return res.status(204).end() | 299 | return res.status(204).end() |
287 | } | 300 | } |