2020-07-14 09:15:20 +00:00
|
|
|
//! # Settings controller
|
|
|
|
//!
|
|
|
|
//! @author Pierre Hubert
|
|
|
|
|
|
|
|
use crate::api_data::general_settings_api::GeneralSettingsAPI;
|
|
|
|
use crate::controllers::routes::RequestResult;
|
2020-07-14 09:36:15 +00:00
|
|
|
use crate::data::general_settings::GeneralSettings;
|
2020-07-14 09:15:20 +00:00
|
|
|
use crate::data::http_request_handler::HttpRequestHandler;
|
2020-07-14 09:36:15 +00:00
|
|
|
use crate::data::user::UserPageStatus;
|
|
|
|
use crate::helpers::{account_helper, user_helper};
|
|
|
|
use crate::helpers::virtual_directory_helper::VirtualDirType;
|
2020-07-14 09:15:20 +00:00
|
|
|
|
|
|
|
/// Get the general settings of the user
|
|
|
|
pub fn get_general(r: &mut HttpRequestHandler) -> RequestResult {
|
|
|
|
let user = user_helper::find_user_by_id(r.user_id_ref()?)?;
|
|
|
|
|
|
|
|
r.set_response(GeneralSettingsAPI::new(&user))
|
2020-07-14 09:36:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Set the general settings of the user
|
|
|
|
pub fn set_general(r: &mut HttpRequestHandler) -> RequestResult {
|
|
|
|
let page_status = match (r.post_bool("isPublic")?, r.post_bool("isOpen")?) {
|
|
|
|
(true, true) => UserPageStatus::OPEN,
|
|
|
|
(true, false) => UserPageStatus::PUBLIC,
|
|
|
|
(_, _) => UserPageStatus::PRIVATE,
|
|
|
|
};
|
|
|
|
|
|
|
|
let personal_website = r.post_url_opt("personnalWebsite", false)?;
|
|
|
|
|
|
|
|
let virtual_directory = r.post_checked_virtual_directory_opt(
|
|
|
|
"virtualDirectory", r.user_id_ref()?.id(), VirtualDirType::USER)?;
|
|
|
|
|
|
|
|
let new_settings = GeneralSettings {
|
|
|
|
id: r.user_id()?,
|
|
|
|
first_name: r.post_content("firstName", 3, true)?,
|
|
|
|
last_name: r.post_content("lastName", 3, true)?,
|
|
|
|
page_status,
|
|
|
|
block_comments: !r.post_bool("allowComments")?,
|
|
|
|
allow_posts_from_friends: r.post_bool("allowPostsFromFriends")?,
|
|
|
|
friends_list_public: r.post_bool("publicFriendsList")?,
|
|
|
|
personal_website,
|
|
|
|
virtual_directory,
|
|
|
|
allow_mails: r.post_bool("allow_comunic_mails")?,
|
|
|
|
public_note: Some(r.post_content("publicNote", 0, false)?),
|
|
|
|
};
|
|
|
|
|
|
|
|
account_helper::set_general(&new_settings)?;
|
|
|
|
|
|
|
|
r.success("Settings updated")
|
2020-07-14 09:15:20 +00:00
|
|
|
}
|