mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2024-12-29 06:58:51 +00:00
Can get general settings
This commit is contained in:
parent
beafd7a26b
commit
46dce030d7
@ -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)},
|
||||
|
||||
|
39
src/controllers/SettingsController.ts
Normal file
39
src/controllers/SettingsController.ts
Normal file
@ -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,
|
||||
})
|
||||
}
|
||||
|
||||
}
|
@ -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
|
||||
|
@ -193,6 +193,7 @@ export class UserHelper {
|
||||
private static async DbToUser(row: any) : Promise<User> {
|
||||
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,
|
||||
|
Loading…
Reference in New Issue
Block a user