1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2024-12-28 14:38:52 +00:00

Update (save) new language settings

This commit is contained in:
Pierre HUBERT 2020-03-21 18:54:30 +01:00
parent 2842fdc55f
commit 02ee59817a
4 changed files with 44 additions and 8 deletions

View File

@ -89,6 +89,8 @@ export const Routes : Route[] = [
{path: "/settings/get_language", cb: (h) => SettingsController.GetLanguage(h)},
{path: "/settings/set_language", cb: (h) => SettingsController.SetLanguage(h)},
// Friends controller
{path: "/friends/getList", cb: (h) => FriendsController.GetList(h)},

View File

@ -6,10 +6,8 @@
import { RequestHandler } from "../entities/RequestHandler";
import { UserHelper } from "../helpers/UserHelper";
import { UserController } from "./UserController";
import { GeneralSettings, User, UserPageStatus } from "../entities/User";
import { GeneralSettings, UserPageStatus, SupportedLanguages, LangSettings } from "../entities/User";
import { removeHTMLNodes, checkURL } from "../utils/StringUtils";
import { VirtualDirectoryController } from "./VirtualDirectoryController";
import { checkVirtualDirectoryAvailability, VirtualDirType } from "../utils/VirtualDirsUtils";
import { AccountHelper } from "../helpers/AccountHelper";
@ -109,13 +107,32 @@ export class SettingsController {
* @param h Request handler
*/
public static async GetLanguage(h: RequestHandler) {
const userInfo = await UserHelper.GetUserInfo(h.getUserId());
h.send({
lang: userInfo.lang
});
}
/**
* Update (set) language settings
*
* @param h Request handler
*/
public static async SetLanguage(h: RequestHandler) {
const lang = h.postString("lang", 2);
if(!SupportedLanguages.includes(lang))
h.error(401, "Language not supported!");
const newSettings: LangSettings = {
id: h.getUserId(),
lang: lang
}
await AccountHelper.SetLanguageSettings(newSettings);
h.success();
}
}

View File

@ -6,14 +6,14 @@ import { AccountImage } from "./AccountImage";
* @author Pierre HUBERT
*/
export const SupportedLanguages = ["fr", "en"]
export enum UserPageStatus {
PRIVATE,
PUBLIC,
OPEN
}
export interface UserInfo {
id: number,
firstName: string,

View File

@ -5,7 +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";
import { GeneralSettings, UserPageStatus, LangSettings } from "../entities/User";
/**
* Account helper
@ -337,4 +337,21 @@ export class AccountHelper {
}
});
}
/**
* Set (save) new language settings
*
* @param settings New settings
*/
public static async SetLanguageSettings(settings: LangSettings) {
await DatabaseHelper.UpdateRows({
table: USER_TABLE,
where: {
ID: settings.id
},
set: {
lang: settings.lang
}
});
}
}