1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2024-12-27 22:18:52 +00:00

Move userID dection

This commit is contained in:
Pierre HUBERT 2020-03-31 14:16:04 +02:00
parent fc5de4c73e
commit b742114854
2 changed files with 29 additions and 28 deletions

View File

@ -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
*

View File

@ -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
*