mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2024-11-23 05:49:22 +00:00
Can set language settings
This commit is contained in:
parent
5a1093b33a
commit
66ad111719
@ -92,3 +92,6 @@ pub const PASSWORD_RESET_TOKEN_LIFETIME: u64 = 60 * 60 * 6;
|
|||||||
|
|
||||||
/// Minimum password length
|
/// Minimum password length
|
||||||
pub const PASSWORD_MIN_LENGTH: usize = 3;
|
pub const PASSWORD_MIN_LENGTH: usize = 3;
|
||||||
|
|
||||||
|
/// Supported languages (for ComunicWeb)
|
||||||
|
pub const SUPPORTED_LANGUAGES: &'static [&'static str] = &["en", "fr"];
|
@ -97,6 +97,7 @@ pub fn get_routes() -> Vec<Route> {
|
|||||||
Route::post("/settings/set_general", Box::new(settings_controller::set_general)),
|
Route::post("/settings/set_general", Box::new(settings_controller::set_general)),
|
||||||
Route::post("/settings/check_user_directory_availability", Box::new(settings_controller::check_virtual_directory)),
|
Route::post("/settings/check_user_directory_availability", Box::new(settings_controller::check_virtual_directory)),
|
||||||
Route::post("/settings/get_language", Box::new(settings_controller::get_language)),
|
Route::post("/settings/get_language", Box::new(settings_controller::get_language)),
|
||||||
|
Route::post("/settings/set_language", Box::new(settings_controller::set_language)),
|
||||||
|
|
||||||
// Friends controller
|
// Friends controller
|
||||||
Route::post("/friends/getList", Box::new(friends_controller::get_list)),
|
Route::post("/friends/getList", Box::new(friends_controller::get_list)),
|
||||||
|
@ -4,9 +4,11 @@
|
|||||||
|
|
||||||
use crate::api_data::general_settings_api::GeneralSettingsAPI;
|
use crate::api_data::general_settings_api::GeneralSettingsAPI;
|
||||||
use crate::api_data::language_settings_api::LanguageSettingsAPI;
|
use crate::api_data::language_settings_api::LanguageSettingsAPI;
|
||||||
|
use crate::constants::SUPPORTED_LANGUAGES;
|
||||||
use crate::controllers::routes::RequestResult;
|
use crate::controllers::routes::RequestResult;
|
||||||
use crate::data::general_settings::GeneralSettings;
|
use crate::data::general_settings::GeneralSettings;
|
||||||
use crate::data::http_request_handler::HttpRequestHandler;
|
use crate::data::http_request_handler::HttpRequestHandler;
|
||||||
|
use crate::data::lang_settings::LangSettings;
|
||||||
use crate::data::user::UserPageStatus;
|
use crate::data::user::UserPageStatus;
|
||||||
use crate::helpers::{account_helper, user_helper};
|
use crate::helpers::{account_helper, user_helper};
|
||||||
use crate::helpers::virtual_directory_helper::VirtualDirType;
|
use crate::helpers::virtual_directory_helper::VirtualDirType;
|
||||||
@ -64,3 +66,21 @@ pub fn get_language(r: &mut HttpRequestHandler) -> RequestResult {
|
|||||||
|
|
||||||
r.set_response(LanguageSettingsAPI::new(&user))
|
r.set_response(LanguageSettingsAPI::new(&user))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Set the current language of the user
|
||||||
|
pub fn set_language(r: &mut HttpRequestHandler) -> RequestResult {
|
||||||
|
let lang = r.post_string("lang")?;
|
||||||
|
|
||||||
|
if !SUPPORTED_LANGUAGES.contains(&lang.as_str()) {
|
||||||
|
r.forbidden("Language not supported!".to_string())?;
|
||||||
|
}
|
||||||
|
|
||||||
|
let new_settings = LangSettings {
|
||||||
|
id: r.user_id()?,
|
||||||
|
lang,
|
||||||
|
};
|
||||||
|
|
||||||
|
account_helper::set_language_settings(&new_settings)?;
|
||||||
|
|
||||||
|
r.success("Language settings updated.")
|
||||||
|
}
|
10
src/data/lang_settings.rs
Normal file
10
src/data/lang_settings.rs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
//! # Language settings
|
||||||
|
//!
|
||||||
|
//! @author Pierre Hubert
|
||||||
|
|
||||||
|
use crate::data::user::UserID;
|
||||||
|
|
||||||
|
pub struct LangSettings {
|
||||||
|
pub id: UserID,
|
||||||
|
pub lang: String,
|
||||||
|
}
|
@ -31,3 +31,4 @@ pub mod account_export;
|
|||||||
pub mod user_like;
|
pub mod user_like;
|
||||||
pub mod survey_response;
|
pub mod survey_response;
|
||||||
pub mod general_settings;
|
pub mod general_settings;
|
||||||
|
pub mod lang_settings;
|
@ -4,6 +4,7 @@ use crate::data::account_export::AccountExport;
|
|||||||
use crate::data::api_client::APIClient;
|
use crate::data::api_client::APIClient;
|
||||||
use crate::data::error::{ExecError, ResultBoxError};
|
use crate::data::error::{ExecError, ResultBoxError};
|
||||||
use crate::data::general_settings::GeneralSettings;
|
use crate::data::general_settings::GeneralSettings;
|
||||||
|
use crate::data::lang_settings::LangSettings;
|
||||||
use crate::data::new_account::NewAccount;
|
use crate::data::new_account::NewAccount;
|
||||||
use crate::data::user::{UserID, UserPageStatus};
|
use crate::data::user::{UserID, UserPageStatus};
|
||||||
use crate::data::user_token::UserAccessToken;
|
use crate::data::user_token::UserAccessToken;
|
||||||
@ -211,6 +212,14 @@ pub fn set_general(settings: &GeneralSettings) -> ResultBoxError {
|
|||||||
.exec()
|
.exec()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Set new language settings
|
||||||
|
pub fn set_language_settings(settings: &LangSettings) -> ResultBoxError {
|
||||||
|
database::UpdateInfo::new(USERS_TABLE)
|
||||||
|
.cond_user_id("ID", &settings.id)
|
||||||
|
.set_str("lang", &settings.lang)
|
||||||
|
.exec()
|
||||||
|
}
|
||||||
|
|
||||||
/// Export an account's data
|
/// Export an account's data
|
||||||
pub fn export(user_id: &UserID) -> ResultBoxError<AccountExport> {
|
pub fn export(user_id: &UserID) -> ResultBoxError<AccountExport> {
|
||||||
let mut data = AccountExport {
|
let mut data = AccountExport {
|
||||||
|
Loading…
Reference in New Issue
Block a user