mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2024-11-26 15:29:22 +00:00
146 lines
3.3 KiB
TypeScript
146 lines
3.3 KiB
TypeScript
import { AccountImage } from "./AccountImage";
|
|
|
|
/**
|
|
* User information
|
|
*
|
|
* @author Pierre HUBERT
|
|
*/
|
|
|
|
export const SupportedLanguages = ["fr", "en"]
|
|
|
|
export enum UserPageStatus {
|
|
PRIVATE,
|
|
PUBLIC,
|
|
OPEN
|
|
}
|
|
|
|
export interface UserInfo {
|
|
id: number,
|
|
firstName: string,
|
|
lastName: string,
|
|
timeCreate: number,
|
|
virtualDirectory: string,
|
|
pageStatus: UserPageStatus,
|
|
accountImage: AccountImage,
|
|
friendsListPublic: boolean,
|
|
personnalWebsite ?: string,
|
|
publicNote ?: string,
|
|
blockComments : boolean,
|
|
allowPostsFromFriends: boolean,
|
|
}
|
|
|
|
export interface GeneralSettings {
|
|
id: number,
|
|
email ?: string,
|
|
firstName: string,
|
|
lastName: string,
|
|
pageStatus: UserPageStatus,
|
|
blockComments: boolean,
|
|
allowPostsFromFriends: boolean,
|
|
friendsListPublic: boolean,
|
|
personnalWebsite ?: string,
|
|
virtualDirectory: string,
|
|
allowMails: boolean,
|
|
publicNote ?: string
|
|
}
|
|
|
|
export interface LangSettings {
|
|
id: number,
|
|
lang: string,
|
|
}
|
|
|
|
export interface SecuritySettings {
|
|
id: number,
|
|
security_question_1 ?: string,
|
|
security_answer_1 ?: string,
|
|
security_question_2 ?: string,
|
|
security_answer_2 ?: string
|
|
}
|
|
|
|
|
|
export interface UserBuilder extends UserInfo, SecuritySettings, LangSettings, GeneralSettings {
|
|
|
|
}
|
|
|
|
export class User implements UserBuilder {
|
|
id: number;
|
|
email: string;
|
|
firstName: string;
|
|
lastName: string;
|
|
timeCreate: number;
|
|
virtualDirectory: string;
|
|
pageStatus: UserPageStatus;
|
|
accountImage: AccountImage;
|
|
friendsListPublic: boolean;
|
|
personnalWebsite?: string;
|
|
publicNote?: string;
|
|
blockComments: boolean;
|
|
allowPostsFromFriends: boolean;
|
|
allowMails: boolean;
|
|
lang: string;
|
|
security_question_1?: string;
|
|
security_answer_1?: string;
|
|
security_question_2?: string;
|
|
security_answer_2?: string;
|
|
|
|
|
|
public constructor(info : UserBuilder) {
|
|
for (const key in info) {
|
|
if (info.hasOwnProperty(key)) {
|
|
this[key] = info[key];
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
get isPublic() : boolean {
|
|
return this.pageStatus != UserPageStatus.PRIVATE;
|
|
}
|
|
|
|
get isOpen() : boolean {
|
|
return this.pageStatus == UserPageStatus.OPEN;
|
|
}
|
|
|
|
get hasVirtualDirectory() : boolean {
|
|
return this.virtualDirectory != null
|
|
&& this.virtualDirectory != "null"
|
|
&& this.virtualDirectory.length > 0
|
|
}
|
|
|
|
get hasWebsite() : boolean {
|
|
return this.personnalWebsite
|
|
&& this.personnalWebsite != null
|
|
&& this.personnalWebsite.length > 0
|
|
&& this.personnalWebsite != "null"
|
|
}
|
|
|
|
get hasPublicNote() : boolean {
|
|
return this.publicNote
|
|
&& this.publicNote != null
|
|
&& this.publicNote.length > 0
|
|
&& this.publicNote != "null"
|
|
}
|
|
|
|
get hasSecurityQuestion1() : boolean {
|
|
return this.security_question_1 != null && this.security_question_1 && this.security_question_1.length > 0;
|
|
}
|
|
|
|
|
|
get hasSecurityAnswer1() : boolean {
|
|
return this.security_answer_1 != null && this.security_answer_1 && this.security_answer_1.length > 0;
|
|
}
|
|
|
|
get hasSecurityQuestion2() : boolean {
|
|
return this.security_question_2 != null && this.security_question_2 != null && this.security_question_2 && this.security_question_2.length > 0;
|
|
}
|
|
|
|
|
|
get hasSecurityAnswer2() : boolean {
|
|
return this.security_answer_2 != null && this.security_answer_2 && this.security_answer_2.length > 0;
|
|
}
|
|
|
|
get hasSecurityQuestions() : boolean {
|
|
return (this.hasSecurityQuestion1 && this.hasSecurityAnswer1
|
|
&& this.hasSecurityQuestion2 && this.hasSecurityAnswer2) == true;
|
|
}
|
|
} |