mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2024-11-22 21:39:21 +00:00
Can set security settings
This commit is contained in:
parent
c9544e7c9c
commit
77d11a8210
@ -99,6 +99,7 @@ pub fn get_routes() -> Vec<Route> {
|
||||
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)),
|
||||
Route::post("/settings/set_security", Box::new(settings_controller::set_security)),
|
||||
|
||||
// Friends controller
|
||||
Route::post("/friends/getList", Box::new(friends_controller::get_list)),
|
||||
|
@ -10,6 +10,7 @@ use crate::controllers::routes::RequestResult;
|
||||
use crate::data::general_settings::GeneralSettings;
|
||||
use crate::data::http_request_handler::HttpRequestHandler;
|
||||
use crate::data::lang_settings::LangSettings;
|
||||
use crate::data::security_settings::{SecurityQuestion, SecuritySettings};
|
||||
use crate::data::user::UserPageStatus;
|
||||
use crate::helpers::{account_helper, user_helper};
|
||||
use crate::helpers::virtual_directory_helper::VirtualDirType;
|
||||
@ -94,3 +95,25 @@ pub fn get_security(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
|
||||
r.set_response(SecuritySettingsAPI::new(&user))
|
||||
}
|
||||
|
||||
/// Set security settings
|
||||
pub fn set_security(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
r.need_user_password("password")?;
|
||||
|
||||
let new_settings = SecuritySettings {
|
||||
id: r.user_id()?,
|
||||
question1: SecurityQuestion::new(
|
||||
&Option::Some(r.post_content("security_question_1", 0, false)?),
|
||||
&Option::Some(r.post_content("security_answer_1", 0, false)?),
|
||||
),
|
||||
|
||||
question2: SecurityQuestion::new(
|
||||
&Option::Some(r.post_content("security_question_2", 0, false)?),
|
||||
&Option::Some(r.post_content("security_answer_2", 0, false)?),
|
||||
),
|
||||
};
|
||||
|
||||
account_helper::set_security_settings(&new_settings)?;
|
||||
|
||||
r.success("Security settings update.")
|
||||
}
|
@ -32,3 +32,4 @@ pub mod user_like;
|
||||
pub mod survey_response;
|
||||
pub mod general_settings;
|
||||
pub mod lang_settings;
|
||||
pub mod security_settings;
|
32
src/data/security_settings.rs
Normal file
32
src/data/security_settings.rs
Normal file
@ -0,0 +1,32 @@
|
||||
//! # Security settings
|
||||
//!
|
||||
//! Security settings of a user
|
||||
|
||||
use crate::data::user::UserID;
|
||||
|
||||
pub struct SecurityQuestion(Option<String>, Option<String>);
|
||||
|
||||
impl SecurityQuestion
|
||||
{
|
||||
pub fn new(question: &Option<String>, answer: &Option<String>) -> SecurityQuestion
|
||||
{
|
||||
SecurityQuestion(question.clone(), answer.clone())
|
||||
}
|
||||
|
||||
pub fn question(&self) -> Option<String>
|
||||
{
|
||||
self.0.clone()
|
||||
}
|
||||
|
||||
pub fn answer(&self) -> Option<String>
|
||||
{
|
||||
self.1.clone()
|
||||
}
|
||||
}
|
||||
|
||||
pub struct SecuritySettings
|
||||
{
|
||||
pub id: UserID,
|
||||
pub question1: SecurityQuestion,
|
||||
pub question2: SecurityQuestion,
|
||||
}
|
@ -12,6 +12,7 @@ use crate::helpers::{comments_helper, conversations_helper, database, friends_he
|
||||
use crate::helpers::database::{DeleteQuery, InsertQuery, QueryInfo};
|
||||
use crate::utils::crypt_utils::{crypt_pass, rand_str};
|
||||
use crate::utils::date_utils::{mysql_date, time};
|
||||
use crate::data::security_settings::SecuritySettings;
|
||||
|
||||
/// Account helper
|
||||
///
|
||||
@ -220,6 +221,17 @@ pub fn set_language_settings(settings: &LangSettings) -> ResultBoxError {
|
||||
.exec()
|
||||
}
|
||||
|
||||
/// Set new security settings
|
||||
pub fn set_security_settings(settings: &SecuritySettings) -> ResultBoxError {
|
||||
database::UpdateInfo::new(USERS_TABLE)
|
||||
.cond_user_id("ID", &settings.id)
|
||||
.set_opt_str("question1", settings.question1.question())
|
||||
.set_opt_str("reponse1", settings.question1.answer())
|
||||
.set_opt_str("question2", settings.question2.question())
|
||||
.set_opt_str("reponse2", settings.question2.answer())
|
||||
.exec()
|
||||
}
|
||||
|
||||
/// Export an account's data
|
||||
pub fn export(user_id: &UserID) -> ResultBoxError<AccountExport> {
|
||||
let mut data = AccountExport {
|
||||
|
Loading…
Reference in New Issue
Block a user