mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2024-11-22 13:29:22 +00:00
Update (save) new language settings
This commit is contained in:
parent
2842fdc55f
commit
02ee59817a
@ -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)},
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
@ -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,
|
||||
|
@ -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
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user