use serde::{Deserialize, Serialize}; use crate::data::http_request_handler::HttpRequestHandler; use crate::controllers::routes::RequestResult; use crate::helpers::account_helper; /// Account controller /// /// @author Pierre Hubert #[derive(Serialize, Deserialize)] struct LoginTokens { token1: String, token2: String, } #[derive(Serialize, Deserialize)] struct LoginSuccess { tokens: LoginTokens } /// 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 { tokens: LoginTokens { token1: t, token2: "dummy_data".to_string() } }) }, Err(e) => { // TODO : limit request println!("Error on login: {}", e); request.forbidden("Invalid email address / password!".to_string()) }, } }