diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..a695b14 --- /dev/null +++ b/Dockerfile @@ -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"] \ No newline at end of file diff --git a/migrations/20220627132425_userup.sql.sql b/migrations/20220627132425_userup.sql.sql index d1fd45c..6e29235 100644 --- a/migrations/20220627132425_userup.sql.sql +++ b/migrations/20220627132425_userup.sql.sql @@ -2,6 +2,7 @@ CREATE TABLE IF NOT EXISTS user ( id INT AUTO_INCREMENT PRIMARY KEY, time_created DATETIME, last_updated DATETIME, + app VARCHAR(255) NOT NULL, email VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, password TEXT NOT NULL, diff --git a/sql/schema/user/find_with_email.sql b/sql/schema/user/find_with_email.sql index 1d14774..d682909 100644 --- a/sql/schema/user/find_with_email.sql +++ b/sql/schema/user/find_with_email.sql @@ -1,3 +1,4 @@ SELECT * FROM user -WHERE user.email = ? \ No newline at end of file +WHERE user.email = ? AND +app = ? \ No newline at end of file diff --git a/sql/schema/user/insert.sql b/sql/schema/user/insert.sql index 4fd03c1..884f59e 100644 --- a/sql/schema/user/insert.sql +++ b/sql/schema/user/insert.sql @@ -1,3 +1,3 @@ INSERT INTO user -(id, time_created, last_updated, email, name, password, salt) values -(NULL, NOW(), NOW(), ?, ?, ?, ?) \ No newline at end of file +(id, time_created, last_updated, email, app, name, password, salt) values +(NULL, NOW(), NOW(), ?, ?, ?, ?, ?) \ No newline at end of file diff --git a/src/dao/user_dao.rs b/src/dao/user_dao.rs index 72c266f..ac31438 100644 --- a/src/dao/user_dao.rs +++ b/src/dao/user_dao.rs @@ -4,11 +4,11 @@ use crate::r#do::user::User; pub async fn insert_user(conn: &mut MySqlConnection, user_to_insert: &User) -> Result{ 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 } -pub async fn find_user_by_email(conn: &mut MySqlConnection, email: &String) -> Result{ - sqlx::query_file_as!(User, "sql/schema/user/find_with_email.sql", email).fetch_one(conn).await +pub async fn find_user_by_email(conn: &mut MySqlConnection, email: &String, app: &String) -> Result{ + 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>{ // Ok(()) diff --git a/src/do/user.rs b/src/do/user.rs index c43f87c..082fcea 100644 --- a/src/do/user.rs +++ b/src/do/user.rs @@ -8,6 +8,7 @@ pub struct User{ pub id: i32, pub time_created: Option, pub last_updated: Option, + pub app: String, pub email: String, pub name: String, pub password: String, @@ -18,6 +19,7 @@ impl User { User { id: 0, time_created: 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(), name:"".to_string(), password:"".to_string(), @@ -27,6 +29,7 @@ impl User { User { id: 0, time_created: 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(), name: incoming_user.name.to_string(), password: incoming_user.password.to_string(), diff --git a/src/dto/user_dtos.rs b/src/dto/user_dtos.rs index 3344d83..b061890 100644 --- a/src/dto/user_dtos.rs +++ b/src/dto/user_dtos.rs @@ -2,17 +2,20 @@ use serde::{Serialize, Deserialize}; #[derive(Serialize, Deserialize, Debug)] pub struct UserForCreationDto{ + pub app: String, pub email: String, pub password: String, pub name: String } #[derive(Serialize, Deserialize, Debug)] pub struct UserForLoginDto{ + pub app: String, pub email: String, pub password: String } #[derive(Serialize, Deserialize, Debug)] pub struct UserForAuthenticationDto{ + pub app: String, pub email: String, pub token: String } \ No newline at end of file diff --git a/src/routes/user_routes.rs b/src/routes/user_routes.rs index 8ba4d24..ac828fe 100644 --- a/src/routes/user_routes.rs +++ b/src/routes/user_routes.rs @@ -31,7 +31,7 @@ pub async fn create_user(incoming_user: web::Json, db_conn: user_validator::validate_user_for_creation(incoming_user_obj, &mut message_resources); // 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) => { message_resources.push(MessageResourceDto::new_from_error_message(ERROR_USER_ALREADY_EXISTS)); return HttpResponse::BadRequest().json(web::Json(message_resources)); @@ -87,7 +87,7 @@ pub async fn authenticate_user_with_password(incoming_user: web::Json 0 { return HttpResponse::BadRequest().json(web::Json(message_resources)); } // 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}, Err(_e) => { message_resources.push(MessageResourceDto::new_from_error_message(ERROR_USER_DOES_NOT_EXIST));