mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2024-11-22 13:29:21 +00:00
Create new api_data module
This commit is contained in:
parent
d2035a6a3f
commit
5554197310
28
src/api_data/login_success.rs
Normal file
28
src/api_data/login_success.rs
Normal file
@ -0,0 +1,28 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Data sent in case of successful login
|
||||
///
|
||||
/// @author Pierre Hubert
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct LoginTokens {
|
||||
token1: String,
|
||||
token2: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct LoginSuccess {
|
||||
success: String,
|
||||
tokens: LoginTokens,
|
||||
}
|
||||
|
||||
impl LoginSuccess {
|
||||
pub fn new(token: &str) -> LoginSuccess {
|
||||
LoginSuccess {
|
||||
success: "Login successful".to_string(),
|
||||
tokens: LoginTokens {
|
||||
token1: token.to_string(),
|
||||
token2: "dummy_data".to_string(),
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
9
src/api_data/mod.rs
Normal file
9
src/api_data/mod.rs
Normal file
@ -0,0 +1,9 @@
|
||||
///! # Presentation
|
||||
///! This crate contains all the serializable structures that can be sent through the API to the
|
||||
///! Clients
|
||||
///!
|
||||
///! ## Author
|
||||
///! Pierre Hubert
|
||||
|
||||
pub mod http_error;
|
||||
pub mod login_success;
|
@ -1,23 +1,12 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use crate::data::http_request_handler::HttpRequestHandler;
|
||||
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
|
||||
|
||||
#[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")?;
|
||||
@ -31,17 +20,12 @@ pub fn login_user(request: &mut HttpRequestHandler) -> RequestResult {
|
||||
|
||||
match token {
|
||||
Ok(t) => {
|
||||
request.set_response(LoginSuccess {
|
||||
tokens: LoginTokens {
|
||||
token1: t,
|
||||
token2: "dummy_data".to_string()
|
||||
}
|
||||
})
|
||||
},
|
||||
request.set_response(LoginSuccess::new(&t))
|
||||
}
|
||||
Err(e) => {
|
||||
// TODO : limit request
|
||||
println!("Error on login: {}", e);
|
||||
request.forbidden("Invalid email address / password!".to_string())
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
@ -2,7 +2,6 @@ use actix_web::{App, HttpResponse, HttpServer, web, http, FromRequest, HttpReque
|
||||
|
||||
use crate::controllers::routes::{get_routes, Route, RequestResult};
|
||||
use crate::data::config::Config;
|
||||
use crate::data::http_error::HttpError;
|
||||
use crate::controllers::routes::Method::{GET, POST};
|
||||
use crate::data::http_request_handler::{HttpRequestHandler, RequestValue};
|
||||
use actix_web::dev::{PayloadStream, Payload, Decompress};
|
||||
@ -13,6 +12,7 @@ use actix_web::error::{ErrorBadRequest};
|
||||
use encoding_rs::UTF_8;
|
||||
use std::collections::HashMap;
|
||||
use percent_encoding::{percent_decode_str};
|
||||
use crate::api_data::http_error::HttpError;
|
||||
|
||||
|
||||
/// Main server functions
|
||||
|
@ -1,6 +1,5 @@
|
||||
use actix_web::{web, HttpRequest, HttpResponse};
|
||||
use crate::controllers::routes::RequestResult;
|
||||
use crate::data::http_error::HttpError;
|
||||
use std::error::Error;
|
||||
use serde::Serialize;
|
||||
use crate::data::error::{ResultBoxError, ExecError};
|
||||
@ -10,6 +9,7 @@ use actix_web::http::{HeaderName, HeaderValue};
|
||||
use std::str::FromStr;
|
||||
use crate::data::config::conf;
|
||||
use crate::data::api_client::APIClient;
|
||||
use crate::api_data::http_error::HttpError;
|
||||
|
||||
/// Http request handler
|
||||
///
|
||||
|
@ -1,7 +1,6 @@
|
||||
pub mod error;
|
||||
pub mod config;
|
||||
|
||||
pub mod http_error;
|
||||
pub mod http_request_handler;
|
||||
pub mod api_client;
|
||||
|
||||
|
@ -1,4 +1,6 @@
|
||||
pub mod data;
|
||||
pub mod helpers;
|
||||
pub mod controllers;
|
||||
pub mod api_data;
|
||||
|
||||
pub mod database_structure;
|
Loading…
Reference in New Issue
Block a user