mirror of
				https://gitlab.com/comunic/comunicapiv3
				synced 2025-11-04 01:24:04 +00:00 
			
		
		
		
	Can check if security questions has been defined
This commit is contained in:
		@@ -44,3 +44,4 @@ pub mod notification_api;
 | 
				
			|||||||
pub mod user_membership_api;
 | 
					pub mod user_membership_api;
 | 
				
			||||||
mod type_container_api;
 | 
					mod type_container_api;
 | 
				
			||||||
pub mod res_check_email_exists;
 | 
					pub mod res_check_email_exists;
 | 
				
			||||||
 | 
					pub mod res_check_security_questions_exists;
 | 
				
			||||||
@@ -4,7 +4,6 @@
 | 
				
			|||||||
use serde::Serialize;
 | 
					use serde::Serialize;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[derive(Serialize)]
 | 
					#[derive(Serialize)]
 | 
				
			||||||
#[allow(non_snake_case)]
 | 
					 | 
				
			||||||
pub struct ResCheckEmailExists {
 | 
					pub struct ResCheckEmailExists {
 | 
				
			||||||
    exists: bool
 | 
					    exists: bool
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										15
									
								
								src/api_data/res_check_security_questions_exists.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								src/api_data/res_check_security_questions_exists.rs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,15 @@
 | 
				
			|||||||
 | 
					//! # Check if security questions are set for a user
 | 
				
			||||||
 | 
					//!
 | 
				
			||||||
 | 
					//! @author Pierre Hubert
 | 
				
			||||||
 | 
					use serde::Serialize;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#[derive(Serialize)]
 | 
				
			||||||
 | 
					pub struct ResCheckSecurityQuestionsExists {
 | 
				
			||||||
 | 
					    defined: bool
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					impl ResCheckSecurityQuestionsExists {
 | 
				
			||||||
 | 
					    pub fn new(defined: bool) -> ResCheckSecurityQuestionsExists {
 | 
				
			||||||
 | 
					        ResCheckSecurityQuestionsExists { defined }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -1,6 +1,7 @@
 | 
				
			|||||||
use crate::api_data::current_user_id::CurrentUserID;
 | 
					use crate::api_data::current_user_id::CurrentUserID;
 | 
				
			||||||
use crate::api_data::login_success::LoginSuccess;
 | 
					use crate::api_data::login_success::LoginSuccess;
 | 
				
			||||||
use crate::api_data::res_check_email_exists::ResCheckEmailExists;
 | 
					use crate::api_data::res_check_email_exists::ResCheckEmailExists;
 | 
				
			||||||
 | 
					use crate::api_data::res_check_security_questions_exists::ResCheckSecurityQuestionsExists;
 | 
				
			||||||
use crate::controllers::routes::RequestResult;
 | 
					use crate::controllers::routes::RequestResult;
 | 
				
			||||||
use crate::data::error::ResultBoxError;
 | 
					use crate::data::error::ResultBoxError;
 | 
				
			||||||
use crate::data::http_request_handler::HttpRequestHandler;
 | 
					use crate::data::http_request_handler::HttpRequestHandler;
 | 
				
			||||||
@@ -79,7 +80,5 @@ pub fn exists_mail(r: &mut HttpRequestHandler) -> RequestResult {
 | 
				
			|||||||
pub fn has_security_questions(r: &mut HttpRequestHandler) -> RequestResult {
 | 
					pub fn has_security_questions(r: &mut HttpRequestHandler) -> RequestResult {
 | 
				
			||||||
    let user = r.post_user_info_from_email("email")?;
 | 
					    let user = r.post_user_info_from_email("email")?;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // TODO : continue implementation
 | 
					    r.set_response(ResCheckSecurityQuestionsExists::new(user.has_security_questions()))
 | 
				
			||||||
    println!("{:#?}", user);
 | 
					 | 
				
			||||||
    r.success("implement me")
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -68,6 +68,10 @@ pub struct User {
 | 
				
			|||||||
    pub block_comments_on_his_page: bool,
 | 
					    pub block_comments_on_his_page: bool,
 | 
				
			||||||
    pub allow_posts_from_friends: bool,
 | 
					    pub allow_posts_from_friends: bool,
 | 
				
			||||||
    pub account_creation_time: u64,
 | 
					    pub account_creation_time: u64,
 | 
				
			||||||
 | 
					    pub security_question_1: Option<String>,
 | 
				
			||||||
 | 
					    pub security_answer_1: Option<String>,
 | 
				
			||||||
 | 
					    pub security_question_2: Option<String>,
 | 
				
			||||||
 | 
					    pub security_answer_2: Option<String>,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
impl User {
 | 
					impl User {
 | 
				
			||||||
@@ -86,4 +90,12 @@ impl User {
 | 
				
			|||||||
    pub fn has_account_image(&self) -> bool {
 | 
					    pub fn has_account_image(&self) -> bool {
 | 
				
			||||||
        self.account_image_path.is_some()
 | 
					        self.account_image_path.is_some()
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /// Check out whether security questions have been defined for this user or not
 | 
				
			||||||
 | 
					    pub fn has_security_questions(&self) -> bool {
 | 
				
			||||||
 | 
					        self.security_question_1.is_some() &&
 | 
				
			||||||
 | 
					            self.security_answer_1.is_some() &&
 | 
				
			||||||
 | 
					            self.security_question_2.is_some() &&
 | 
				
			||||||
 | 
					            self.security_answer_2.is_some()
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -64,6 +64,10 @@ fn exec_get_user_query(query: database::QueryInfo) -> ResultBoxError<User> {
 | 
				
			|||||||
            block_comments_on_his_page: res.get_legacy_bool("bloquecommentaire")?,
 | 
					            block_comments_on_his_page: res.get_legacy_bool("bloquecommentaire")?,
 | 
				
			||||||
            allow_posts_from_friends: res.get_legacy_bool("autoriser_post_amis")?,
 | 
					            allow_posts_from_friends: res.get_legacy_bool("autoriser_post_amis")?,
 | 
				
			||||||
            account_creation_time: res.get_date_as_time("date_creation")?,
 | 
					            account_creation_time: res.get_date_as_time("date_creation")?,
 | 
				
			||||||
 | 
					            security_question_1: res.get_optional_str("question1")?,
 | 
				
			||||||
 | 
					            security_answer_1: res.get_optional_str("reponse1")?,
 | 
				
			||||||
 | 
					            security_question_2: res.get_optional_str("question2")?,
 | 
				
			||||||
 | 
					            security_answer_2: res.get_optional_str("reponse2")?,
 | 
				
			||||||
        })
 | 
					        })
 | 
				
			||||||
    })
 | 
					    })
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user