mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2025-06-20 08:35:17 +00:00
Update (save) new language settings
This commit is contained in:
@ -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();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user