From b742114854b4e1c13e6c589b8fc29eb754144e97 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Tue, 31 Mar 2020 14:16:04 +0200 Subject: [PATCH] Move userID dection --- src/entities/BaseRequestsHandler.ts | 27 ++++++++++++++++++++++++++ src/entities/RequestHandler.ts | 30 ++--------------------------- 2 files changed, 29 insertions(+), 28 deletions(-) diff --git a/src/entities/BaseRequestsHandler.ts b/src/entities/BaseRequestsHandler.ts index 7d145bb..d2d281d 100644 --- a/src/entities/BaseRequestsHandler.ts +++ b/src/entities/BaseRequestsHandler.ts @@ -9,12 +9,39 @@ import { removeHTMLNodes, checkMail } from "../utils/StringUtils"; export abstract class BaseRequestsHandler { + protected abstract get userID() : number; + protected abstract getPostParam(name : string) : any; public abstract hasPostParameter(name: string) : boolean; public abstract error(code : number, message : string) : void; public abstract success(message: string) : void; public abstract send(data: any): void; + /** + * Get information about current user + */ + public getUserId() : number { + if(this.userID < 1) + throw Error("Trying to get user ID but none are available!"); + + return this.userID; + } + + /** + * Get the ID of the current user (if any) + * or 0 if the user is not signed in + */ + public get optionnalUserID(): number { + return this.userID >= 1 ? this.userID : 0; + } + + /** + * Check out whether user is signed in or not + */ + public get signedIn() : boolean { + return this.userID > 0; + } + /** * Check out whether a POST string is present in the request or not * diff --git a/src/entities/RequestHandler.ts b/src/entities/RequestHandler.ts index fd5ad43..b1dc8fd 100644 --- a/src/entities/RequestHandler.ts +++ b/src/entities/RequestHandler.ts @@ -2,12 +2,11 @@ import { conf } from "../helpers/ConfigHelper"; import { Response, Request } from "express"; import { APIHelper } from "../helpers/APIHelper"; import { APIClient } from "./APIClient"; -import { checkMail, removeHTMLNodes, checkURL } from "../utils/StringUtils"; +import { checkURL } from "../utils/StringUtils"; 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"; import { GroupsAccessLevel } from "./Group"; import { GroupsHelper } from "../helpers/GroupsHelper"; import { checkVirtualDirectory } from "../utils/VirtualDirsUtils"; @@ -27,7 +26,7 @@ import { BaseRequestsHandler } from "./BaseRequestsHandler"; export class RequestHandler extends BaseRequestsHandler { private client : APIClient = null; - private userID : number = -1; + protected userID : number = -1; private responseSent = false; @@ -375,31 +374,6 @@ export class RequestHandler extends BaseRequestsHandler { return this.client; } - /** - * Get information about current user - */ - public getUserId() : number { - if(this.userID < 1) - throw Error("Trying to get user ID but none are available!"); - - return this.userID; - } - - /** - * Get the ID of the current user (if any) - * or 0 if the user is not signed in - */ - public get optionnalUserID(): number { - return this.userID >= 1 ? this.userID : 0; - } - - /** - * Check out whether user is signed in or not - */ - public get signedIn() : boolean { - return this.userID > 0; - } - /** * Output an error code and throws an error *