Added dockerfile

This commit is contained in:
franklinblanco 2022-07-08 14:35:19 -04:00
parent b34b0a87d0
commit 57f88e5101
8 changed files with 25 additions and 8 deletions

9
Dockerfile Normal file
View File

@ -0,0 +1,9 @@
FROM rust:1.31
WORKDIR /usr/src/user-svc
RUN cargo build --release
COPY ./target/release/user-svc-actix .
CMD ["user-svc-actix"]

View File

@ -2,6 +2,7 @@ CREATE TABLE IF NOT EXISTS user (
id INT AUTO_INCREMENT PRIMARY KEY, id INT AUTO_INCREMENT PRIMARY KEY,
time_created DATETIME, time_created DATETIME,
last_updated DATETIME, last_updated DATETIME,
app VARCHAR(255) NOT NULL,
email VARCHAR(255) NOT NULL, email VARCHAR(255) NOT NULL,
name VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL,
password TEXT NOT NULL, password TEXT NOT NULL,

View File

@ -1,3 +1,4 @@
SELECT * SELECT *
FROM user FROM user
WHERE user.email = ? WHERE user.email = ? AND
app = ?

View File

@ -1,3 +1,3 @@
INSERT INTO user INSERT INTO user
(id, time_created, last_updated, email, name, password, salt) values (id, time_created, last_updated, email, app, name, password, salt) values
(NULL, NOW(), NOW(), ?, ?, ?, ?) (NULL, NOW(), NOW(), ?, ?, ?, ?, ?)

View File

@ -4,11 +4,11 @@ use crate::r#do::user::User;
pub async fn insert_user(conn: &mut MySqlConnection, user_to_insert: &User) -> Result<MySqlQueryResult, sqlx::Error>{ pub async fn insert_user(conn: &mut MySqlConnection, user_to_insert: &User) -> Result<MySqlQueryResult, sqlx::Error>{
sqlx::query_file!("sql/schema/user/insert.sql", sqlx::query_file!("sql/schema/user/insert.sql",
user_to_insert.email, user_to_insert.name, user_to_insert.password, user_to_insert.salt) user_to_insert.app, user_to_insert.email, user_to_insert.name, user_to_insert.password, user_to_insert.salt)
.execute(conn).await .execute(conn).await
} }
pub async fn find_user_by_email(conn: &mut MySqlConnection, email: &String) -> Result<User, sqlx::Error>{ pub async fn find_user_by_email(conn: &mut MySqlConnection, email: &String, app: &String) -> Result<User, sqlx::Error>{
sqlx::query_file_as!(User, "sql/schema/user/find_with_email.sql", email).fetch_one(conn).await sqlx::query_file_as!(User, "sql/schema/user/find_with_email.sql", email, app).fetch_one(conn).await
} }
//pub async fn _update_user(conn: &mut MySqlConnection, user_to_modify: &User) -> Result<(), sqlx::Error>{ //pub async fn _update_user(conn: &mut MySqlConnection, user_to_modify: &User) -> Result<(), sqlx::Error>{
// Ok(()) // Ok(())

View File

@ -8,6 +8,7 @@ pub struct User{
pub id: i32, pub id: i32,
pub time_created: Option<NaiveDateTime>, pub time_created: Option<NaiveDateTime>,
pub last_updated: Option<NaiveDateTime>, pub last_updated: Option<NaiveDateTime>,
pub app: String,
pub email: String, pub email: String,
pub name: String, pub name: String,
pub password: String, pub password: String,
@ -18,6 +19,7 @@ impl User {
User { id: 0, User { id: 0,
time_created: None, // This will be automatically generated from the database time_created: None, // This will be automatically generated from the database
last_updated: None, // This will be automatically generated from the database last_updated: None, // This will be automatically generated from the database
app: "".to_string(),
email: "".to_string(), email: "".to_string(),
name:"".to_string(), name:"".to_string(),
password:"".to_string(), password:"".to_string(),
@ -27,6 +29,7 @@ impl User {
User { id: 0, User { id: 0,
time_created: None, // This will be automatically generated from the database time_created: None, // This will be automatically generated from the database
last_updated: None, // This will be automatically generated from the database last_updated: None, // This will be automatically generated from the database
app: incoming_user.app.to_string(),
email: incoming_user.email.to_string(), email: incoming_user.email.to_string(),
name: incoming_user.name.to_string(), name: incoming_user.name.to_string(),
password: incoming_user.password.to_string(), password: incoming_user.password.to_string(),

View File

@ -2,17 +2,20 @@ use serde::{Serialize, Deserialize};
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug)]
pub struct UserForCreationDto{ pub struct UserForCreationDto{
pub app: String,
pub email: String, pub email: String,
pub password: String, pub password: String,
pub name: String pub name: String
} }
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug)]
pub struct UserForLoginDto{ pub struct UserForLoginDto{
pub app: String,
pub email: String, pub email: String,
pub password: String pub password: String
} }
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug)]
pub struct UserForAuthenticationDto{ pub struct UserForAuthenticationDto{
pub app: String,
pub email: String, pub email: String,
pub token: String pub token: String
} }

View File

@ -31,7 +31,7 @@ pub async fn create_user(incoming_user: web::Json<UserForCreationDto>, db_conn:
user_validator::validate_user_for_creation(incoming_user_obj, &mut message_resources); user_validator::validate_user_for_creation(incoming_user_obj, &mut message_resources);
// Find if user exists // Find if user exists
match find_user_by_email(&mut db_conn.lock().unwrap(), &user_to_insert.email).await{ match find_user_by_email(&mut db_conn.lock().unwrap(), &user_to_insert.email, &user_to_insert.app).await{
Ok(_usr) => { Ok(_usr) => {
message_resources.push(MessageResourceDto::new_from_error_message(ERROR_USER_ALREADY_EXISTS)); message_resources.push(MessageResourceDto::new_from_error_message(ERROR_USER_ALREADY_EXISTS));
return HttpResponse::BadRequest().json(web::Json(message_resources)); return HttpResponse::BadRequest().json(web::Json(message_resources));
@ -87,7 +87,7 @@ pub async fn authenticate_user_with_password(incoming_user: web::Json<UserForLog
if message_resources.len() > 0 { return HttpResponse::BadRequest().json(web::Json(message_resources)); } if message_resources.len() > 0 { return HttpResponse::BadRequest().json(web::Json(message_resources)); }
// If user exists get it, if it doesn't blow up to the client // If user exists get it, if it doesn't blow up to the client
let persisted_user = match find_user_by_email(&mut db_conn.lock().unwrap(), &incoming_user_obj.email).await { let persisted_user = match find_user_by_email(&mut db_conn.lock().unwrap(), &incoming_user_obj.email, &incoming_user_obj.app).await {
Ok(rs) => {rs}, Ok(rs) => {rs},
Err(_e) => { Err(_e) => {
message_resources.push(MessageResourceDto::new_from_error_message(ERROR_USER_DOES_NOT_EXIST)); message_resources.push(MessageResourceDto::new_from_error_message(ERROR_USER_DOES_NOT_EXIST));