mirror of
				https://gitlab.com/comunic/comunicapiv2
				synced 2025-11-04 03:24:04 +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/get_language", cb: (h) => SettingsController.GetLanguage(h)},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						{path: "/settings/set_language", cb: (h) => SettingsController.SetLanguage(h)},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Friends controller
 | 
						// Friends controller
 | 
				
			||||||
	{path: "/friends/getList", cb: (h) => FriendsController.GetList(h)},
 | 
						{path: "/friends/getList", cb: (h) => FriendsController.GetList(h)},
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -6,10 +6,8 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import { RequestHandler } from "../entities/RequestHandler";
 | 
					import { RequestHandler } from "../entities/RequestHandler";
 | 
				
			||||||
import { UserHelper } from "../helpers/UserHelper";
 | 
					import { UserHelper } from "../helpers/UserHelper";
 | 
				
			||||||
import { UserController } from "./UserController";
 | 
					import { GeneralSettings, UserPageStatus, SupportedLanguages, LangSettings } from "../entities/User";
 | 
				
			||||||
import { GeneralSettings, User, UserPageStatus } from "../entities/User";
 | 
					 | 
				
			||||||
import { removeHTMLNodes, checkURL } from "../utils/StringUtils";
 | 
					import { removeHTMLNodes, checkURL } from "../utils/StringUtils";
 | 
				
			||||||
import { VirtualDirectoryController } from "./VirtualDirectoryController";
 | 
					 | 
				
			||||||
import { checkVirtualDirectoryAvailability, VirtualDirType } from "../utils/VirtualDirsUtils";
 | 
					import { checkVirtualDirectoryAvailability, VirtualDirType } from "../utils/VirtualDirsUtils";
 | 
				
			||||||
import { AccountHelper } from "../helpers/AccountHelper";
 | 
					import { AccountHelper } from "../helpers/AccountHelper";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -109,13 +107,32 @@ export class SettingsController {
 | 
				
			|||||||
	 * @param h Request handler
 | 
						 * @param h Request handler
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	public static async GetLanguage(h: RequestHandler) {
 | 
						public static async GetLanguage(h: RequestHandler) {
 | 
				
			||||||
 | 
					 | 
				
			||||||
		const userInfo = await UserHelper.GetUserInfo(h.getUserId());
 | 
							const userInfo = await UserHelper.GetUserInfo(h.getUserId());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		h.send({
 | 
							h.send({
 | 
				
			||||||
			lang: userInfo.lang
 | 
								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
 | 
					 * @author Pierre HUBERT
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const SupportedLanguages = ["fr", "en"]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export enum UserPageStatus {
 | 
					export enum UserPageStatus {
 | 
				
			||||||
	PRIVATE,
 | 
						PRIVATE,
 | 
				
			||||||
	PUBLIC,
 | 
						PUBLIC,
 | 
				
			||||||
	OPEN
 | 
						OPEN
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
export interface UserInfo  {
 | 
					export interface UserInfo  {
 | 
				
			||||||
	id: number,
 | 
						id: number,
 | 
				
			||||||
	firstName: string,
 | 
						firstName: string,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -5,7 +5,7 @@ import { DatabaseHelper } from "./DatabaseHelper";
 | 
				
			|||||||
import { UserHelper } from "./UserHelper";
 | 
					import { UserHelper } from "./UserHelper";
 | 
				
			||||||
import { time, mysql_date } from "../utils/DateUtils";
 | 
					import { time, mysql_date } from "../utils/DateUtils";
 | 
				
			||||||
import { NewAccount } from "../entities/NewAccount";
 | 
					import { NewAccount } from "../entities/NewAccount";
 | 
				
			||||||
import { GeneralSettings, UserPageStatus } from "../entities/User";
 | 
					import { GeneralSettings, UserPageStatus, LangSettings } from "../entities/User";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Account helper
 | 
					 * 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
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							});
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user