mirror of
				https://gitlab.com/comunic/comunicapiv3
				synced 2025-11-04 01:24:04 +00:00 
			
		
		
		
	Ready to implement password check
This commit is contained in:
		
							
								
								
									
										21
									
								
								src/helpers/account_helper.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								src/helpers/account_helper.rs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,21 @@
 | 
			
		||||
use crate::data::api_client::APIClient;
 | 
			
		||||
use crate::data::error::ResultBoxError;
 | 
			
		||||
use crate::helpers::user_helper;
 | 
			
		||||
 | 
			
		||||
/// Account helper
 | 
			
		||||
///
 | 
			
		||||
/// @author Pierre Hubert
 | 
			
		||||
 | 
			
		||||
/// Attempt to sign-in user
 | 
			
		||||
///
 | 
			
		||||
/// In this version of the api, we consider that there is only one login token required
 | 
			
		||||
/// This is why I returns just a simple string, the token created for the user in case of success
 | 
			
		||||
pub fn login_user(email: &str, password: &str, client: &APIClient) -> ResultBoxError<String> {
 | 
			
		||||
    let user = user_helper::find_user_by_email(email)?;
 | 
			
		||||
 | 
			
		||||
    // TODO : check user password
 | 
			
		||||
 | 
			
		||||
    println!("{:#?}", user);
 | 
			
		||||
 | 
			
		||||
    Ok("d".to_string())
 | 
			
		||||
}
 | 
			
		||||
@@ -1,3 +1,5 @@
 | 
			
		||||
pub mod database;
 | 
			
		||||
 | 
			
		||||
pub mod api_helper;
 | 
			
		||||
pub mod api_helper;
 | 
			
		||||
pub mod account_helper;
 | 
			
		||||
pub mod user_helper;
 | 
			
		||||
							
								
								
									
										27
									
								
								src/helpers/user_helper.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								src/helpers/user_helper.rs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,27 @@
 | 
			
		||||
use crate::data::error::ResultBoxError;
 | 
			
		||||
use crate::data::user::User;
 | 
			
		||||
use crate::helpers::database;
 | 
			
		||||
use crate::database_structure::USERS_TABLE;
 | 
			
		||||
 | 
			
		||||
/// User helper
 | 
			
		||||
///
 | 
			
		||||
/// @author Pierre Hubert
 | 
			
		||||
 | 
			
		||||
/// Get & return information about a user based on his email
 | 
			
		||||
pub fn find_user_by_email(email: &str) -> ResultBoxError<User> {
 | 
			
		||||
    exec_get_user_query(
 | 
			
		||||
        database::QueryInfo::new(USERS_TABLE).cond("mail", email))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// Execute query & return result
 | 
			
		||||
fn exec_get_user_query(query : database::QueryInfo) -> ResultBoxError<User> {
 | 
			
		||||
    database::query_row(query, |res|{
 | 
			
		||||
        Ok(User {
 | 
			
		||||
            id: res.get_int64("ID")?,
 | 
			
		||||
            email: res.get_str("mail")?,
 | 
			
		||||
            password: res.get_str("password")?,
 | 
			
		||||
            first_name: res.get_str("prenom")?,
 | 
			
		||||
            last_name: res.get_str("nom")?
 | 
			
		||||
        })
 | 
			
		||||
    })
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user