From 83ce6dac8a262c735af304bdeab2589a06e7bca8 Mon Sep 17 00:00:00 2001 From: arrelin Date: Sat, 24 Jan 2026 18:06:14 +0300 Subject: [PATCH] dependencies update --- backend/Cargo.toml | 22 ++++----- backend/src/auth.rs | 51 ++++++++++++--------- backend/src/services/invite_link_service.rs | 4 +- 3 files changed, 43 insertions(+), 34 deletions(-) diff --git a/backend/Cargo.toml b/backend/Cargo.toml index 40de145..4b7a713 100644 --- a/backend/Cargo.toml +++ b/backend/Cargo.toml @@ -4,24 +4,24 @@ version = "0.1.0" edition = "2024" [dependencies] -tokio = { version = "1.48.0", features = ["full"] } -sea-orm = { version = "1.0", features = ["sqlx-postgres", "runtime-tokio-rustls", "macros"] } -sea-orm-migration = { version = "1.0", default-features = false, features = ["sqlx-postgres", "runtime-tokio-rustls"] } +tokio = { version = "1.49.0", features = ["full"] } +sea-orm = { version = "1.1.19", features = ["sqlx-postgres", "runtime-tokio-rustls", "macros"] } +sea-orm-migration = { version = "1.1.19", default-features = false, features = ["sqlx-postgres", "runtime-tokio-rustls"] } dotenvy = "0.15.7" -axum = { version = "0.7", features = ["json"] } -tower-http = { version = "0.5", features = ["cors"] } +axum = { version = "0.8.8", features = ["json"] } +tower-http = { version = "0.6.8", features = ["cors"] } chrono = { version = "0.4.42", features = ["serde"] } serde = { version = "1.0.228", features = ["derive"] } serde_json = "1.0" utoipa = { version = "5.4.0", features = ["axum_extras", "chrono", "decimal_float"] } -utoipa-swagger-ui = { version = "8.0", features = ["axum"] } -axum-login = "0.15" -tower-sessions = "0.12" -tower-sessions-sqlx-store = { version = "0.12", features = ["postgres"] } +utoipa-swagger-ui = { version = "9.0.2", features = ["axum"] } +axum-login = "0.18.0" +tower-sessions = "0.14.0" +tower-sessions-sqlx-store = { version = "0.15.0", features = ["postgres"] } argon2 = "0.5" async-trait = "0.1" thiserror = "2.0" time = "0.3" oauth2 = { version = "5.0.0", features = ["reqwest"] } -reqwest = { version = "0.12.28", features = ["json"] } -rand = "0.8" \ No newline at end of file +reqwest = { version = "0.13.1", features = ["json"] } +rand = "0.9.2" \ No newline at end of file diff --git a/backend/src/auth.rs b/backend/src/auth.rs index b84e82f..17d85a1 100644 --- a/backend/src/auth.rs +++ b/backend/src/auth.rs @@ -40,43 +40,52 @@ pub struct Credentials { pub password: String, } -#[async_trait::async_trait] impl AuthnBackend for AuthBackend { type User = user::Model; type Credentials = Credentials; type Error = Error; - async fn authenticate( + fn authenticate( &self, creds: Self::Credentials, - ) -> Result, Self::Error> { - let user = User::find() - .filter(user::Column::Username.eq(&creds.username)) - .one(&self.db) - .await?; + ) -> impl Future, Self::Error>> + Send { + let db = self.db.clone(); + async move { + let user = User::find() + .filter(user::Column::Username.eq(&creds.username)) + .one(&db) + .await?; - if let Some(user) = user { - let password_hash = user.password_hash.as_ref().ok_or(Error::InvalidCredentials)?; - let parsed_hash = PasswordHash::new(password_hash) - .map_err(|_| Error::PasswordHash)?; + if let Some(user) = user { + let password_hash = user.password_hash.as_ref().ok_or(Error::InvalidCredentials)?; + let parsed_hash = PasswordHash::new(password_hash) + .map_err(|_| Error::PasswordHash)?; - let is_valid = Argon2::default() - .verify_password(creds.password.as_bytes(), &parsed_hash) - .is_ok(); + let is_valid = Argon2::default() + .verify_password(creds.password.as_bytes(), &parsed_hash) + .is_ok(); - if is_valid { - Ok(Some(user)) + if is_valid { + Ok(Some(user)) + } else { + Err(Error::InvalidCredentials) + } } else { Err(Error::InvalidCredentials) } - } else { - Err(Error::InvalidCredentials) } } - async fn get_user(&self, user_id: &UserId) -> Result, Self::Error> { - let user = User::find_by_id(*user_id).one(&self.db).await?; - Ok(user) + fn get_user( + &self, + user_id: &UserId, + ) -> impl Future, Self::Error>> + Send { + let db = self.db.clone(); + let user_id = *user_id; + async move { + let user = User::find_by_id(user_id).one(&db).await?; + Ok(user) + } } } diff --git a/backend/src/services/invite_link_service.rs b/backend/src/services/invite_link_service.rs index 054a488..4e01a6b 100644 --- a/backend/src/services/invite_link_service.rs +++ b/backend/src/services/invite_link_service.rs @@ -1,5 +1,5 @@ use sea_orm::*; -use rand::distributions::Alphanumeric; +use rand::distr::Alphanumeric; use rand::Rng; use crate::models::invite_link::{self, Entity as InviteLink, Model as InviteLinkModel}; use crate::models::{user, User}; @@ -8,7 +8,7 @@ pub struct InviteLinkService; impl InviteLinkService { pub fn generate_token() -> String { - rand::thread_rng() + rand::rng() .sample_iter(&Alphanumeric) .take(32) .map(char::from)