1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2025-06-21 00:45:18 +00:00

Ready to implement password check

This commit is contained in:
2020-05-23 19:17:48 +02:00
parent 975c129f7c
commit d2035a6a3f
9 changed files with 130 additions and 8 deletions

View 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())
}

View File

@ -1,3 +1,5 @@
pub mod database;
pub mod api_helper;
pub mod api_helper;
pub mod account_helper;
pub mod user_helper;

View 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")?
})
})
}