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

Can get security questions

This commit is contained in:
Pierre HUBERT 2020-07-13 13:23:37 +02:00
parent e76b3180e7
commit 1974c782b5
4 changed files with 36 additions and 1 deletions

View File

@ -45,3 +45,4 @@ pub mod user_membership_api;
mod type_container_api;
pub mod res_check_email_exists;
pub mod res_check_security_questions_exists;
pub mod res_get_security_questions;

View File

@ -0,0 +1,21 @@
//! # Get security questions results
//!
//! @author Pierre Hubert
use serde::Serialize;
use crate::data::user::User;
#[derive(Serialize)]
pub struct ResGetSecurityQuestions {
questions: Vec<String>
}
impl ResGetSecurityQuestions {
pub fn new(user: &User) -> ResGetSecurityQuestions {
let mut questions = Vec::new();
questions.push(user.security_question_1.clone().unwrap_or(String::new()));
questions.push(user.security_question_2.clone().unwrap_or(String::new()));
ResGetSecurityQuestions { questions }
}
}

View File

@ -2,6 +2,7 @@ use crate::api_data::current_user_id::CurrentUserID;
use crate::api_data::login_success::LoginSuccess;
use crate::api_data::res_check_email_exists::ResCheckEmailExists;
use crate::api_data::res_check_security_questions_exists::ResCheckSecurityQuestionsExists;
use crate::api_data::res_get_security_questions::ResGetSecurityQuestions;
use crate::controllers::routes::RequestResult;
use crate::data::error::ResultBoxError;
use crate::data::http_request_handler::HttpRequestHandler;
@ -82,3 +83,14 @@ pub fn has_security_questions(r: &mut HttpRequestHandler) -> RequestResult {
r.set_response(ResCheckSecurityQuestionsExists::new(user.has_security_questions()))
}
/// Get the security questions of a user
pub fn get_security_questions(r: &mut HttpRequestHandler) -> RequestResult {
let user = r.post_user_info_from_email("email")?;
if !user.has_security_questions() {
r.forbidden("Specified user has not defined security questions!".to_string())?;
}
r.set_response(ResGetSecurityQuestions::new(&user))
}

View File

@ -76,6 +76,7 @@ pub fn get_routes() -> Vec<Route> {
Route::post("/user/getCurrentUserID", Box::new(account_controller::user_id)),
Route::post_without_login("/account/exists_email", Box::new(account_controller::exists_mail)),
Route::post_without_login("/account/has_security_questions", Box::new(account_controller::has_security_questions)),
Route::post_without_login("/account/get_security_questions", Box::new(account_controller::get_security_questions)),
// User controller
Route::post_without_login("/user/getInfo", Box::new(user_controller::get_single)),