mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2024-11-22 13:29:21 +00:00
Can get current user email address easily
This commit is contained in:
parent
9f6b00a62b
commit
312e6fb949
@ -11,6 +11,7 @@ pub mod server_config;
|
||||
pub mod http_error;
|
||||
pub mod login_success;
|
||||
pub mod current_user_id;
|
||||
pub mod user_mail_address;
|
||||
pub mod user_info;
|
||||
pub mod custom_emoji;
|
||||
pub mod res_find_user_by_virtual_directory;
|
||||
|
20
src/api_data/user_mail_address.rs
Normal file
20
src/api_data/user_mail_address.rs
Normal file
@ -0,0 +1,20 @@
|
||||
//! # Get current user email address result
|
||||
//!
|
||||
//! @author Pierre Hubert
|
||||
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::data::user::User;
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct UserMailAddressAPI {
|
||||
mail: String,
|
||||
}
|
||||
|
||||
impl UserMailAddressAPI {
|
||||
pub fn new(user: &User) -> Self {
|
||||
Self {
|
||||
mail: user.email.to_string()
|
||||
}
|
||||
}
|
||||
}
|
@ -7,6 +7,7 @@ use crate::api_data::res_check_email_exists::ResCheckEmailExists;
|
||||
use crate::api_data::res_check_security_answers::ResCheckSecurityAnswers;
|
||||
use crate::api_data::res_check_security_questions_exists::ResCheckSecurityQuestionsExists;
|
||||
use crate::api_data::res_get_security_questions::ResGetSecurityQuestions;
|
||||
use crate::api_data::user_mail_address::UserMailAddressAPI;
|
||||
use crate::constants::PASSWORD_RESET_TOKEN_LENGTH;
|
||||
use crate::data::base_request_handler::BaseRequestHandler;
|
||||
use crate::data::error::ResultBoxError;
|
||||
@ -110,6 +111,12 @@ pub fn user_id(request: &mut HttpRequestHandler) -> RequestResult {
|
||||
request.set_response(CurrentUserID::new(&request.user_id()?))
|
||||
}
|
||||
|
||||
/// Get current user email address
|
||||
pub fn get_mail(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
let user = user_helper::find_user_by_id(r.user_id_ref()?)?;
|
||||
r.set_response(UserMailAddressAPI::new(&user))
|
||||
}
|
||||
|
||||
/// Check out whether an email address exists or not
|
||||
pub fn exists_mail(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
let email = r.post_email("email")?;
|
||||
|
@ -140,6 +140,7 @@ pub fn get_routes() -> Vec<Route> {
|
||||
Route::post("/user/disconnectUSER", Box::new(account_controller::logout_user)), // TODO : remove
|
||||
Route::post("/account/disconnect_all_devices", Box::new(account_controller::disconnect_all_devices)),
|
||||
Route::post("/account/id", Box::new(account_controller::user_id)),
|
||||
Route::post("/account/mail", Box::new(account_controller::get_mail)),
|
||||
Route::post("/user/getCurrentUserID", Box::new(account_controller::user_id)), // TODO : remove
|
||||
Route::limited_post_without_login("/account/exists_email", Box::new(account_controller::exists_mail), LimitPolicy::ANY(30)),
|
||||
Route::limited_post_without_login("/account/has_security_questions", Box::new(account_controller::has_security_questions), LimitPolicy::FAILURE(10)),
|
||||
|
Loading…
Reference in New Issue
Block a user