mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2024-11-26 07:19:22 +00:00
Can get security questions
This commit is contained in:
parent
e76b3180e7
commit
1974c782b5
@ -44,4 +44,5 @@ pub mod notification_api;
|
||||
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_check_security_questions_exists;
|
||||
pub mod res_get_security_questions;
|
21
src/api_data/res_get_security_questions.rs
Normal file
21
src/api_data/res_get_security_questions.rs
Normal 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 }
|
||||
}
|
||||
}
|
@ -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;
|
||||
@ -81,4 +82,15 @@ pub fn has_security_questions(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
let user = r.post_user_info_from_email("email")?;
|
||||
|
||||
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))
|
||||
}
|
@ -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)),
|
||||
|
Loading…
Reference in New Issue
Block a user