From 190e047bd85d0257e3494aa17b7357615b6b4c04 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Sat, 23 Nov 2019 16:23:36 +0100 Subject: [PATCH] Fix issue with ComunicWeb --- src/controllers/UserController.ts | 16 ++++++++++++++++ src/entities/RequestHandler.ts | 24 ++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/src/controllers/UserController.ts b/src/controllers/UserController.ts index 439cb23..28edb16 100644 --- a/src/controllers/UserController.ts +++ b/src/controllers/UserController.ts @@ -28,7 +28,23 @@ export class UserController { * Get information about multiple users */ public static async GetMultiple(handler : RequestHandler) { + + let list = {}; + const IDs = handler.postNumbersList("usersID"); + for (const id of IDs) { + if(list.hasOwnProperty(id)) + continue; + + const user = await UserHelper.GetUserInfo(id); + + if(!user) + handler.error(404, "One user was not found!"); + + list[id] = this.UserToAPI(user, handler); + } + + handler.send(list); } private static UserToAPI(user : User, handler: RequestHandler) : Object { diff --git a/src/entities/RequestHandler.ts b/src/entities/RequestHandler.ts index 26fcf3b..c4dca9c 100644 --- a/src/entities/RequestHandler.ts +++ b/src/entities/RequestHandler.ts @@ -90,6 +90,30 @@ export class RequestHandler { } + /** + * Get a list of integeres included in the request + * + * @param name The name of the post field + */ + public postNumbersList(name: string) : Array { + const param = this.postString(name); + let list = []; + for (const el of param.split(",")) { + + if(el == "") + continue; + + if(Number.parseInt(el).toString() != el) + this.error(400, "Invalid number detected in '"+name+"'!"); + + list.push(Number.parseInt(el)); + + } + + return list; + } + + /** * Validate API tokens *