mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2024-12-29 06:58:51 +00:00
Can set (update) general settings
This commit is contained in:
parent
46dce030d7
commit
03100e0bd3
@ -82,7 +82,9 @@ export const Routes : Route[] = [
|
||||
|
||||
// Settings controller
|
||||
{path: "/settings/get_general", cb: (h) => SettingsController.GetGeneral(h)},
|
||||
|
||||
|
||||
{path: "/settings/set_general", cb: (h) => SettingsController.SetGeneral(h)},
|
||||
|
||||
|
||||
// Friends controller
|
||||
{path: "/friends/getList", cb: (h) => FriendsController.GetList(h)},
|
||||
|
@ -7,6 +7,11 @@
|
||||
import { RequestHandler } from "../entities/RequestHandler";
|
||||
import { UserHelper } from "../helpers/UserHelper";
|
||||
import { UserController } from "./UserController";
|
||||
import { GeneralSettings, User, UserPageStatus } from "../entities/User";
|
||||
import { removeHTMLNodes, checkURL } from "../utils/StringUtils";
|
||||
import { VirtualDirectoryController } from "./VirtualDirectoryController";
|
||||
import { checkVirtualDirectoryAvailability, VirtualDirType } from "../utils/VirtualDirsUtils";
|
||||
import { AccountHelper } from "../helpers/AccountHelper";
|
||||
|
||||
export class SettingsController {
|
||||
|
||||
@ -36,4 +41,51 @@ export class SettingsController {
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Update (set) general account settings
|
||||
*
|
||||
* @param h Request handler
|
||||
*/
|
||||
public static async SetGeneral(h: RequestHandler) {
|
||||
|
||||
// Determine page status
|
||||
const pageStatus = h.postBool("isPublic") ? (
|
||||
h.postBool("isOpen") ? UserPageStatus.OPEN : UserPageStatus.PUBLIC
|
||||
) : UserPageStatus.PRIVATE;
|
||||
|
||||
// Check personnal website
|
||||
const personnalWebsite = h.postString("personnalWebsite", 0);
|
||||
if(personnalWebsite.length > 0 && !checkURL(personnalWebsite))
|
||||
h.error(401, "Invalid personnal website supplied!");
|
||||
|
||||
// Check virtual directory
|
||||
let virtualDirectory = h.postString("virtualDirectory", 0);
|
||||
if(virtualDirectory.length > 0) {
|
||||
virtualDirectory = h.postVirtualDirectory("virtualDirectory");
|
||||
|
||||
if(!checkVirtualDirectoryAvailability(virtualDirectory, h.getUserId(), VirtualDirType.USER))
|
||||
h.error(401, "The specified virtual directory is not available!");
|
||||
}
|
||||
|
||||
// Construct new settings object
|
||||
const newSettings : GeneralSettings = {
|
||||
id: h.getUserId(),
|
||||
firstName: removeHTMLNodes(h.postString("firstName", 3)),
|
||||
lastName: removeHTMLNodes(h.postString("lastName", 3)),
|
||||
pageStatus: pageStatus,
|
||||
blockComments: !h.postBool("allowComments"),
|
||||
allowPostsFromFriends: h.postBool("allowPostsFromFriends"),
|
||||
friendsListPublic: h.postBool("publicFriendsList"),
|
||||
personnalWebsite: personnalWebsite,
|
||||
virtualDirectory: virtualDirectory,
|
||||
allowMails: h.postBool("allow_comunic_mails"),
|
||||
publicNote: removeHTMLNodes(h.postString("publicNote", 0))
|
||||
};
|
||||
|
||||
await AccountHelper.SetGeneral(newSettings);
|
||||
|
||||
h.success();
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -16,7 +16,6 @@ export enum UserPageStatus {
|
||||
|
||||
export interface UserInfo {
|
||||
id: number,
|
||||
email: string;
|
||||
firstName: string,
|
||||
lastName: string,
|
||||
timeCreate: number,
|
||||
@ -28,7 +27,21 @@ export interface UserInfo {
|
||||
publicNote ?: string,
|
||||
blockComments : boolean,
|
||||
allowPostsFromFriends: boolean,
|
||||
allowMails: 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 SecuritySettings {
|
||||
@ -40,7 +53,7 @@ export interface SecuritySettings {
|
||||
}
|
||||
|
||||
|
||||
export interface UserBuilder extends UserInfo, SecuritySettings {
|
||||
export interface UserBuilder extends UserInfo, SecuritySettings, GeneralSettings {
|
||||
|
||||
}
|
||||
|
||||
@ -75,7 +88,7 @@ export class User implements UserBuilder {
|
||||
|
||||
|
||||
get isPublic() : boolean {
|
||||
return this.pageStatus == UserPageStatus.PUBLIC;
|
||||
return this.pageStatus != UserPageStatus.PRIVATE;
|
||||
}
|
||||
|
||||
get isOpen() : boolean {
|
||||
|
@ -5,6 +5,7 @@ import { DatabaseHelper } from "./DatabaseHelper";
|
||||
import { UserHelper } from "./UserHelper";
|
||||
import { time, mysql_date } from "../utils/DateUtils";
|
||||
import { NewAccount } from "../entities/NewAccount";
|
||||
import { GeneralSettings, UserPageStatus } from "../entities/User";
|
||||
|
||||
/**
|
||||
* Account helper
|
||||
@ -309,4 +310,31 @@ export class AccountHelper {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Set (save) new general settings
|
||||
*
|
||||
* @param settings New settings
|
||||
*/
|
||||
public static async SetGeneral(settings: GeneralSettings) {
|
||||
await DatabaseHelper.UpdateRows({
|
||||
table: USER_TABLE,
|
||||
where: {
|
||||
ID: settings.id
|
||||
},
|
||||
set: {
|
||||
prenom: settings.firstName,
|
||||
nom: settings.lastName,
|
||||
public: settings.pageStatus != UserPageStatus.PRIVATE ? 1 : 0,
|
||||
pageouverte: settings.pageStatus == UserPageStatus.OPEN ? 1 : 0,
|
||||
bloquecommentaire: settings.blockComments ? 1 : 0,
|
||||
autoriser_post_amis: settings.allowPostsFromFriends ? 1 : 0,
|
||||
autorise_mail: settings.allowMails ? 1 : 0,
|
||||
liste_amis_publique: settings.friendsListPublic ? 1 : 0,
|
||||
sous_repertoire: settings.virtualDirectory,
|
||||
site_web: settings.personnalWebsite,
|
||||
public_note: settings.publicNote
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user