1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2024-11-26 15:29:21 +00:00

Can get security settings

This commit is contained in:
Pierre HUBERT 2021-01-19 17:27:54 +01:00
parent 66ad111719
commit c9544e7c9c
4 changed files with 42 additions and 1 deletions

View File

@ -52,4 +52,5 @@ pub mod user_like_api;
pub mod survey_response_api;
pub mod entities_constructor;
pub mod general_settings_api;
pub mod language_settings_api;
pub mod language_settings_api;
pub mod security_settings_api;

View File

@ -0,0 +1,29 @@
//! # Security settings API
//!
//! @author Pierre Hubert
use serde::Serialize;
use crate::data::user::User;
#[derive(Serialize)]
#[allow(non_snake_case)]
pub struct SecuritySettingsAPI {
id: u64,
security_question_1: String,
security_answer_1: String,
security_question_2: String,
security_answer_2: String,
}
impl SecuritySettingsAPI {
pub fn new(user: &User) -> SecuritySettingsAPI {
SecuritySettingsAPI {
id: user.id.id(),
security_question_1: user.security_question_1.clone().unwrap_or(String::new()),
security_answer_1: user.security_answer_1.clone().unwrap_or(String::new()),
security_question_2: user.security_question_2.clone().unwrap_or(String::new()),
security_answer_2: user.security_answer_2.clone().unwrap_or(String::new()),
}
}
}

View File

@ -98,6 +98,7 @@ pub fn get_routes() -> Vec<Route> {
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/set_language", Box::new(settings_controller::set_language)),
Route::post("/settings/get_security", Box::new(settings_controller::get_security)),
// Friends controller
Route::post("/friends/getList", Box::new(friends_controller::get_list)),

View File

@ -4,6 +4,7 @@
use crate::api_data::general_settings_api::GeneralSettingsAPI;
use crate::api_data::language_settings_api::LanguageSettingsAPI;
use crate::api_data::security_settings_api::SecuritySettingsAPI;
use crate::constants::SUPPORTED_LANGUAGES;
use crate::controllers::routes::RequestResult;
use crate::data::general_settings::GeneralSettings;
@ -83,4 +84,13 @@ pub fn set_language(r: &mut HttpRequestHandler) -> RequestResult {
account_helper::set_language_settings(&new_settings)?;
r.success("Language settings updated.")
}
/// Get security settings
pub fn get_security(r: &mut HttpRequestHandler) -> RequestResult {
r.need_user_password("password")?;
let user = user_helper::find_user_by_id(r.user_id_ref()?)?;
r.set_response(SecuritySettingsAPI::new(&user))
}