diff --git a/database_interactions/simple-auth-server/Cargo.toml b/database_interactions/simple-auth-server/Cargo.toml index 555bb57f..7efb1dad 100644 --- a/database_interactions/simple-auth-server/Cargo.toml +++ b/database_interactions/simple-auth-server/Cargo.toml @@ -5,20 +5,20 @@ edition = "2021" workspace = "../.." [dependencies] -actix-web = "3" -actix-identity = "0.3" +actix-web = "4.0.0-beta.21" +actix-identity = "0.4.0-beta.8" chrono = { version = "0.4.6", features = ["serde"] } derive_more = "0.99.0" diesel = { version = "1.4.5", features = ["postgres", "uuidv07", "r2d2", "chrono"] } dotenv = "0.15" -env_logger = "0.8" +env_logger = "0.9.0" futures = "0.3.1" r2d2 = "0.8" -rust-argon2 = "0.8" +rust-argon2 = "1.0.0" lazy_static = "1.4.0" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" sparkpost = "0.5.2" -uuid = { version = "0.8", features = ["serde", "v4"] } -time = "0.2" +uuid = { version = "0.8.2", features = ["serde", "v4"] } +time = "0.3.7" diff --git a/database_interactions/simple-auth-server/src/auth_handler.rs b/database_interactions/simple-auth-server/src/auth_handler.rs index f08f1fa9..9af6dca1 100644 --- a/database_interactions/simple-auth-server/src/auth_handler.rs +++ b/database_interactions/simple-auth-server/src/auth_handler.rs @@ -1,8 +1,5 @@ use actix_identity::Identity; -use actix_web::{ - dev::Payload, error::BlockingError, web, Error, FromRequest, HttpRequest, - HttpResponse, -}; +use actix_web::{dev::Payload, web, Error, FromRequest, HttpRequest, HttpResponse}; use diesel::prelude::*; use diesel::PgConnection; use futures::future::{err, ok, Ready}; @@ -23,7 +20,6 @@ pub struct AuthData { pub type LoggedUser = SlimUser; impl FromRequest for LoggedUser { - type Config = (); type Error = Error; type Future = Ready>; @@ -48,20 +44,12 @@ pub async fn login( auth_data: web::Json, id: Identity, pool: web::Data, -) -> Result { - let res = web::block(move || query(auth_data.into_inner(), pool)).await; +) -> Result { + let user = web::block(move || query(auth_data.into_inner(), pool)).await??; - match res { - Ok(user) => { - let user_string = serde_json::to_string(&user).unwrap(); - id.remember(user_string); - Ok(HttpResponse::Ok().finish()) - } - Err(err) => match err { - BlockingError::Error(service_error) => Err(service_error), - BlockingError::Canceled => Err(ServiceError::InternalServerError), - }, - } + let user_string = serde_json::to_string(&user).unwrap(); + id.remember(user_string); + Ok(HttpResponse::Ok().finish()) } pub async fn get_me(logged_user: LoggedUser) -> HttpResponse { diff --git a/database_interactions/simple-auth-server/src/invitation_handler.rs b/database_interactions/simple-auth-server/src/invitation_handler.rs index c82521fe..52a44564 100644 --- a/database_interactions/simple-auth-server/src/invitation_handler.rs +++ b/database_interactions/simple-auth-server/src/invitation_handler.rs @@ -1,9 +1,8 @@ -use actix_web::{error::BlockingError, web, HttpResponse}; +use actix_web::{web, HttpResponse}; use diesel::{prelude::*, PgConnection}; use serde::Deserialize; use crate::email_service::send_invitation; -use crate::errors::ServiceError; use crate::models::{Invitation, Pool}; #[derive(Deserialize)] @@ -14,19 +13,12 @@ pub struct InvitationData { pub async fn post_invitation( invitation_data: web::Json, pool: web::Data, -) -> Result { +) -> Result { // run diesel blocking code - let res = - web::block(move || create_invitation(invitation_data.into_inner().email, pool)) - .await; + web::block(move || create_invitation(invitation_data.into_inner().email, pool)) + .await??; - match res { - Ok(_) => Ok(HttpResponse::Ok().finish()), - Err(err) => match err { - BlockingError::Error(service_error) => Err(service_error), - BlockingError::Canceled => Err(ServiceError::InternalServerError), - }, - } + Ok(HttpResponse::Ok().finish()) } fn create_invitation( diff --git a/database_interactions/simple-auth-server/src/main.rs b/database_interactions/simple-auth-server/src/main.rs index 15c131ba..bcdbf376 100644 --- a/database_interactions/simple-auth-server/src/main.rs +++ b/database_interactions/simple-auth-server/src/main.rs @@ -37,7 +37,7 @@ async fn main() -> std::io::Result<()> { // Start http server HttpServer::new(move || { App::new() - .data(pool.clone()) + .app_data(web::Data::new(pool.clone())) // enable logger .wrap(middleware::Logger::default()) .wrap(IdentityService::new( @@ -45,10 +45,10 @@ async fn main() -> std::io::Result<()> { .name("auth") .path("/") .domain(domain.as_str()) - .max_age_time(Duration::days(1)) + .max_age(Duration::days(1)) .secure(false), // this can only be true if you have https )) - .data(web::JsonConfig::default().limit(4096)) + .app_data(web::JsonConfig::default().limit(4096)) // everything under '/api/' route .service( web::scope("/api") diff --git a/database_interactions/simple-auth-server/src/register_handler.rs b/database_interactions/simple-auth-server/src/register_handler.rs index f8127245..071f8524 100644 --- a/database_interactions/simple-auth-server/src/register_handler.rs +++ b/database_interactions/simple-auth-server/src/register_handler.rs @@ -1,4 +1,4 @@ -use actix_web::{error::BlockingError, web, HttpResponse}; +use actix_web::{web, HttpResponse}; use diesel::prelude::*; use serde::Deserialize; @@ -15,23 +15,17 @@ pub async fn register_user( invitation_id: web::Path, user_data: web::Json, pool: web::Data, -) -> Result { - let res = web::block(move || { +) -> Result { + let user = web::block(move || { query( invitation_id.into_inner(), user_data.into_inner().password, pool, ) }) - .await; + .await??; - match res { - Ok(user) => Ok(HttpResponse::Ok().json(&user)), - Err(err) => match err { - BlockingError::Error(service_error) => Err(service_error), - BlockingError::Canceled => Err(ServiceError::InternalServerError), - }, - } + Ok(HttpResponse::Ok().json(&user)) } fn query(