1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2024-11-23 22:09:22 +00:00
comunicapiv3/src/controllers/account_controller.rs

31 lines
906 B
Rust

use crate::api_data::login_success::LoginSuccess;
use crate::controllers::routes::RequestResult;
use crate::data::http_request_handler::HttpRequestHandler;
use crate::helpers::account_helper;
/// Account controller
///
/// @author Pierre Hubert
/// Sign in user
pub fn login_user(request: &mut HttpRequestHandler) -> RequestResult {
let email = request.post_email("userMail")?;
let password = request.post_string_opt("userPassword", 3, true)?;
// TODO : limit request
// Authenticate user
let token = account_helper::login_user(
&email, &password, request.api_client());
match token {
Ok(t) => {
request.set_response(LoginSuccess::new(&t))
}
Err(e) => {
// TODO : limit request
println!("Error on login: {}", e);
request.forbidden("Invalid email address / password!".to_string())
}
}
}