1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2024-11-26 23:39:22 +00:00
comunicapiv3/src/helpers/user_helper.rs

27 lines
817 B
Rust
Raw Normal View History

2020-05-23 17:17:48 +00:00
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")?
})
})
}