mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2024-11-22 13:29:22 +00:00
Move userID dection
This commit is contained in:
parent
fc5de4c73e
commit
b742114854
@ -9,12 +9,39 @@ import { removeHTMLNodes, checkMail } from "../utils/StringUtils";
|
|||||||
|
|
||||||
export abstract class BaseRequestsHandler {
|
export abstract class BaseRequestsHandler {
|
||||||
|
|
||||||
|
protected abstract get userID() : number;
|
||||||
|
|
||||||
protected abstract getPostParam(name : string) : any;
|
protected abstract getPostParam(name : string) : any;
|
||||||
public abstract hasPostParameter(name: string) : boolean;
|
public abstract hasPostParameter(name: string) : boolean;
|
||||||
public abstract error(code : number, message : string) : void;
|
public abstract error(code : number, message : string) : void;
|
||||||
public abstract success(message: string) : void;
|
public abstract success(message: string) : void;
|
||||||
public abstract send(data: any): 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
|
* Check out whether a POST string is present in the request or not
|
||||||
*
|
*
|
||||||
|
@ -2,12 +2,11 @@ import { conf } from "../helpers/ConfigHelper";
|
|||||||
import { Response, Request } from "express";
|
import { Response, Request } from "express";
|
||||||
import { APIHelper } from "../helpers/APIHelper";
|
import { APIHelper } from "../helpers/APIHelper";
|
||||||
import { APIClient } from "./APIClient";
|
import { APIClient } from "./APIClient";
|
||||||
import { checkMail, removeHTMLNodes, checkURL } from "../utils/StringUtils";
|
import { checkURL } from "../utils/StringUtils";
|
||||||
import { AccountHelper } from "../helpers/AccountHelper";
|
import { AccountHelper } from "../helpers/AccountHelper";
|
||||||
import { UploadedFile } from "express-fileupload";
|
import { UploadedFile } from "express-fileupload";
|
||||||
import { prepareFileCreation, generateNewUserDataFileName, pathUserData } from "../utils/UserDataUtils";
|
import { prepareFileCreation, generateNewUserDataFileName, pathUserData } from "../utils/UserDataUtils";
|
||||||
import * as sharp from 'sharp';
|
import * as sharp from 'sharp';
|
||||||
import { UserHelper } from "../helpers/UserHelper";
|
|
||||||
import { GroupsAccessLevel } from "./Group";
|
import { GroupsAccessLevel } from "./Group";
|
||||||
import { GroupsHelper } from "../helpers/GroupsHelper";
|
import { GroupsHelper } from "../helpers/GroupsHelper";
|
||||||
import { checkVirtualDirectory } from "../utils/VirtualDirsUtils";
|
import { checkVirtualDirectory } from "../utils/VirtualDirsUtils";
|
||||||
@ -27,7 +26,7 @@ import { BaseRequestsHandler } from "./BaseRequestsHandler";
|
|||||||
export class RequestHandler extends BaseRequestsHandler {
|
export class RequestHandler extends BaseRequestsHandler {
|
||||||
|
|
||||||
private client : APIClient = null;
|
private client : APIClient = null;
|
||||||
private userID : number = -1;
|
protected userID : number = -1;
|
||||||
|
|
||||||
private responseSent = false;
|
private responseSent = false;
|
||||||
|
|
||||||
@ -375,31 +374,6 @@ export class RequestHandler extends BaseRequestsHandler {
|
|||||||
return this.client;
|
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
|
* Output an error code and throws an error
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user