From 46dce030d71599c5b286913bb4f5dd31efdb7e1d Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Sat, 21 Mar 2020 17:16:30 +0100 Subject: [PATCH] Can get general settings --- src/controllers/Routes.ts | 5 ++++ src/controllers/SettingsController.ts | 39 +++++++++++++++++++++++++++ src/entities/User.ts | 13 +++++++++ src/helpers/UserHelper.ts | 2 ++ 4 files changed, 59 insertions(+) create mode 100644 src/controllers/SettingsController.ts diff --git a/src/controllers/Routes.ts b/src/controllers/Routes.ts index a7ba4c9..ea34f59 100644 --- a/src/controllers/Routes.ts +++ b/src/controllers/Routes.ts @@ -15,6 +15,7 @@ import { PostsController } from "./PostsController"; import { CommentsController } from "./CommentsController"; import { LikesController } from "./LikesController"; import { SurveyController } from "./SurveyController"; +import { SettingsController } from "./SettingsController"; /** * Controllers routes @@ -79,6 +80,10 @@ export const Routes : Route[] = [ {path: "/user/getAdvancedUserInfos", cb: (h) => UserController.GetAdvancedInfo(h), needLogin: false}, // Legacy + // Settings controller + {path: "/settings/get_general", cb: (h) => SettingsController.GetGeneral(h)}, + + // Friends controller {path: "/friends/getList", cb: (h) => FriendsController.GetList(h)}, diff --git a/src/controllers/SettingsController.ts b/src/controllers/SettingsController.ts new file mode 100644 index 0000000..3905c26 --- /dev/null +++ b/src/controllers/SettingsController.ts @@ -0,0 +1,39 @@ +/** + * Settings controller + * + * @author Pierre HUBERT + */ + +import { RequestHandler } from "../entities/RequestHandler"; +import { UserHelper } from "../helpers/UserHelper"; +import { UserController } from "./UserController"; + +export class SettingsController { + + /** + * Get general account settings + * + * @param h Request handler + */ + public static async GetGeneral(h: RequestHandler) { + + const userInfo = await UserHelper.GetUserInfo(h.getUserId()); + + h.send({ + id: userInfo.id, + email: userInfo.email, + firstName: userInfo.firstName, + lastName: userInfo.lastName, + is_public: userInfo.isPublic, + is_open: userInfo.isOpen, + allow_comments: !userInfo.blockComments, + allow_posts_from_friends: userInfo.allowPostsFromFriends, + allow_comunic_mails: userInfo.allowMails, + public_friends_list: userInfo.friendsListPublic, + virtual_directory: userInfo.virtualDirectory, + personnal_website: userInfo.personnalWebsite, + publicNote: userInfo.publicNote, + }) + } + +} \ No newline at end of file diff --git a/src/entities/User.ts b/src/entities/User.ts index 3e0f527..298000a 100644 --- a/src/entities/User.ts +++ b/src/entities/User.ts @@ -16,6 +16,7 @@ export enum UserPageStatus { export interface UserInfo { id: number, + email: string; firstName: string, lastName: string, timeCreate: number, @@ -27,6 +28,7 @@ export interface UserInfo { publicNote ?: string, blockComments : boolean, allowPostsFromFriends: boolean, + allowMails: boolean } export interface SecuritySettings { @@ -44,6 +46,7 @@ export interface UserBuilder extends UserInfo, SecuritySettings { export class User implements UserBuilder { id: number; + email: string; firstName: string; lastName: string; timeCreate: number; @@ -55,6 +58,7 @@ export class User implements UserBuilder { publicNote?: string; blockComments: boolean; allowPostsFromFriends: boolean; + allowMails: boolean; security_question_1?: string; security_answer_1?: string; security_question_2?: string; @@ -68,6 +72,15 @@ export class User implements UserBuilder { } } } + + + get isPublic() : boolean { + return this.pageStatus == UserPageStatus.PUBLIC; + } + + get isOpen() : boolean { + return this.pageStatus == UserPageStatus.OPEN; + } get hasVirtualDirectory() : boolean { return this.virtualDirectory != null diff --git a/src/helpers/UserHelper.ts b/src/helpers/UserHelper.ts index 31f31bd..808e8dc 100644 --- a/src/helpers/UserHelper.ts +++ b/src/helpers/UserHelper.ts @@ -193,6 +193,7 @@ export class UserHelper { private static async DbToUser(row: any) : Promise { return new User({ id: row.ID, + email: row.mail, firstName: row.prenom, lastName: row.nom, timeCreate: new Date(row.date_creation).getTime()/1000, @@ -204,6 +205,7 @@ export class UserHelper { publicNote: row.public_note, blockComments: row.bloquecommentaire == 1, allowPostsFromFriends: row.autoriser_post_amis == 1, + allowMails: row.autorise_mail == 1, security_question_1: row.question1, security_answer_1: row.reponse1, security_question_2: row.question2,