mirror of
				https://gitlab.com/comunic/comunicapiv3
				synced 2025-10-30 23:24:42 +00:00 
			
		
		
		
	Can check if an email address exists or not
This commit is contained in:
		| @@ -42,4 +42,5 @@ pub mod res_number_unread_notifications; | ||||
| pub mod res_count_all_unreads; | ||||
| pub mod notification_api; | ||||
| pub mod user_membership_api; | ||||
| mod type_container_api; | ||||
| mod type_container_api; | ||||
| pub mod res_check_email_exists; | ||||
							
								
								
									
										16
									
								
								src/api_data/res_check_email_exists.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								src/api_data/res_check_email_exists.rs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,16 @@ | ||||
| //! # Check if email exists result | ||||
| //! | ||||
| //! @author Pierre Hubert | ||||
| use serde::Serialize; | ||||
|  | ||||
| #[derive(Serialize)] | ||||
| #[allow(non_snake_case)] | ||||
| pub struct ResCheckEmailExists { | ||||
|     exists: bool | ||||
| } | ||||
|  | ||||
| impl ResCheckEmailExists { | ||||
|     pub fn new(exists: bool) -> ResCheckEmailExists { | ||||
|         ResCheckEmailExists { exists } | ||||
|     } | ||||
| } | ||||
| @@ -1,5 +1,6 @@ | ||||
| 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::controllers::routes::RequestResult; | ||||
| use crate::data::http_request_handler::HttpRequestHandler; | ||||
| use crate::helpers::account_helper; | ||||
| @@ -51,4 +52,11 @@ pub fn disconnect_all_devices(r: &mut HttpRequestHandler) -> RequestResult { | ||||
| /// Get current user ID | ||||
| pub fn user_id(request: &mut HttpRequestHandler) -> RequestResult { | ||||
|     request.set_response(CurrentUserID::new(&request.user_id()?)) | ||||
| } | ||||
|  | ||||
| /// Check out whether an email address exists or not | ||||
| pub fn exists_mail(r: &mut HttpRequestHandler) -> RequestResult { | ||||
|     let email = r.post_email("email")?; | ||||
|  | ||||
|     r.set_response(ResCheckEmailExists::new(account_helper::exists_mail(&email)?)) | ||||
| } | ||||
| @@ -74,6 +74,7 @@ pub fn get_routes() -> Vec<Route> { | ||||
|         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("/user/getCurrentUserID", Box::new(account_controller::user_id)), | ||||
|         Route::post_without_login("/account/exists_email", Box::new(account_controller::exists_mail)), | ||||
|  | ||||
|         // User controller | ||||
|         Route::post_without_login("/user/getInfo", Box::new(user_controller::get_single)), | ||||
|   | ||||
| @@ -77,6 +77,14 @@ pub fn get_user_by_login_token(token: &str, client: &APIClient) -> ResultBoxErro | ||||
|     ) | ||||
| } | ||||
|  | ||||
| /// Check out whether an email address exists or not | ||||
| pub fn exists_mail(mail: &str) -> ResultBoxError<bool> { | ||||
|     database::QueryInfo::new(USERS_TABLE) | ||||
|         .cond("mail", mail) | ||||
|         .exec_count() | ||||
|         .map(|r| r > 0) | ||||
| } | ||||
|  | ||||
| /// Destroy a given user login tokens | ||||
| pub fn destroy_login_tokens(id: &UserID, client: &APIClient) -> ResultBoxError<()> { | ||||
|     database::delete(DeleteQuery::new(USER_ACCESS_TOKENS_TABLE) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user