mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2024-11-22 05:19:22 +00:00
Can safely get the ID of a user in a request
This commit is contained in:
parent
7d6979e096
commit
d348e58ecd
@ -6,6 +6,7 @@ import { AccountHelper } from "../helpers/AccountHelper";
|
||||
import { UploadedFile } from "express-fileupload";
|
||||
import { prepareFileCreation, generateNewUserDataFileName, pathUserData } from "../utils/UserDataUtils";
|
||||
import * as sharp from 'sharp';
|
||||
import { UserHelper } from "../helpers/UserHelper";
|
||||
|
||||
/**
|
||||
* Response to a request
|
||||
@ -162,16 +163,39 @@ export class RequestHandler {
|
||||
* Get a boolean included in the request
|
||||
*
|
||||
* @param name The name of the POST field
|
||||
* @param fallback Fallback value to use if the value is not
|
||||
* found in the request
|
||||
*/
|
||||
public postBool(name: string) : boolean {
|
||||
public postBool(name: string, fallback ?: boolean) : boolean {
|
||||
const param = this.getPostParam(name);
|
||||
|
||||
if(param == undefined)
|
||||
if(param == undefined) {
|
||||
if(fallback != undefined)
|
||||
return fallback;
|
||||
|
||||
this.error(400, "Missing boolean '" + name + "' in the request!");
|
||||
}
|
||||
|
||||
return param === "true" || param === true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the ID of a user specified in a POST request
|
||||
*
|
||||
* @param name Name of the POST field
|
||||
*/
|
||||
public async postUserId(name: string) : Promise<number> {
|
||||
const userID = this.postInt(name);
|
||||
|
||||
if(userID < 1)
|
||||
this.error(400, "Invalid user ID specified in '" + name +"'!");
|
||||
|
||||
if(!await UserHelper.Exists(userID))
|
||||
this.error(404, "User with ID " + userID + " not found!");
|
||||
|
||||
return userID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get information about an uploaded file
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user