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
Raw Normal View History

2020-05-24 11:09:50 +00:00
use crate::api_data::login_success::LoginSuccess;
2020-05-21 13:43:53 +00:00
use crate::controllers::routes::RequestResult;
2020-05-24 11:09:50 +00:00
use crate::data::http_request_handler::HttpRequestHandler;
2020-05-23 17:17:48 +00:00
use crate::helpers::account_helper;
2020-05-21 13:43:53 +00:00
/// Account controller
///
/// @author Pierre Hubert
/// Sign in user
2020-05-23 15:09:28 +00:00
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
2020-05-23 17:17:48 +00:00
let token = account_helper::login_user(
&email, &password, request.api_client());
2020-05-23 15:09:28 +00:00
2020-05-23 17:17:48 +00:00
match token {
Ok(t) => {
2020-05-24 11:09:50 +00:00
request.set_response(LoginSuccess::new(&t))
}
2020-05-23 17:17:48 +00:00
Err(e) => {
// TODO : limit request
println!("Error on login: {}", e);
request.forbidden("Invalid email address / password!".to_string())
2020-05-24 11:09:50 +00:00
}
2020-05-23 17:17:48 +00:00
}
2020-05-21 13:43:53 +00:00
}