Skip to content
This repository was archived by the owner on Aug 5, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ sqlx-mysql = ["sqlx/mysql"]


[dependencies.rusqlite]
version = "0.27.0"
version = "0.30.0"
optional = true


Expand All @@ -44,12 +44,12 @@ futures= "0.3.21"


[dependencies.sqlx]
version = "0.6.0"
version = "0.7.4"
optional = true


[dependencies.rocket]
version = "0.5.0-rc.2"
version = "0.5.0"
features = ["secrets"]

[dependencies.serde]
Expand All @@ -75,7 +75,7 @@ tokio-postgres= "0.7.6"


[dev-dependencies.rocket]
version = "0.5.0-rc.2"
version = "0.5.0"
features = ["secrets", "json"]

[dev-dependencies.redis]
Expand All @@ -84,12 +84,12 @@ features = ["aio", "tokio-comp"]


[dev-dependencies.rocket_dyn_templates]
version = "0.1.0-rc.2"
version = "0.1.0"
features = ["tera"]


[dev-dependencies.sqlx]
version = "0.6.0"
version = "0.7.4"
features = ["runtime-tokio-rustls"]

[dev-dependencies.rocket_auth]
Expand Down
3 changes: 1 addition & 2 deletions src/cookies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ pub struct Session {
pub auth_key: String,
}


#[async_trait]
impl<'r> FromRequest<'r> for Session {
type Error = Error;
Expand All @@ -34,7 +33,7 @@ impl<'r> FromRequest<'r> for Session {
if let Some(session) = get_session(cookies) {
Outcome::Success(session)
} else {
Outcome::Failure((Status::Unauthorized, Error::UnauthorizedError))
Outcome::Error((Status::Unauthorized, Error::UnauthorizedError))
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/user/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl<'r> FromRequest<'r> for Auth<'r> {
let users: &State<Users> = if let Outcome::Success(users) = req.guard().await {
users
} else {
return Outcome::Failure((Status::InternalServerError, Error::UnmanagedStateError));
return Outcome::Error((Status::InternalServerError, Error::UnmanagedStateError));
};

Outcome::Success(Auth {
Expand Down Expand Up @@ -222,7 +222,7 @@ impl<'a> Auth<'a> {
pub fn logout(&self) {
let session = self.get_session()?;
self.users.logout(session)?;
self.cookies.remove_private(Cookie::named("rocket_auth"));
self.cookies.remove_private(Cookie::from("rocket_auth"));
}
/// Deletes the account of the currently authenticated user.
/// ```rust
Expand All @@ -238,7 +238,7 @@ impl<'a> Auth<'a> {
if self.is_auth() {
let session = self.get_session()?;
self.users.delete(session.id).await?;
self.cookies.remove_private(Cookie::named("rocket_auth"));
self.cookies.remove_private(Cookie::from("rocket_auth"));
} else {
throw!(Error::UnauthenticatedError)
}
Expand Down Expand Up @@ -308,7 +308,7 @@ impl<'a> Auth<'a> {
#[throws(Error)]
pub async fn compare_password(&self, password: &str) -> bool {
if self.is_auth() {
let session = self.get_session()?;
let session = self.get_session()?;
let user: User = self.users.get_by_id(session.id).await?;
user.compare_password(password)?
} else {
Expand Down
12 changes: 6 additions & 6 deletions src/user/user_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ impl User {
/// In case the user is authenticated,
/// you can change it more easily with [`change_password`](`super::auth::Auth::change_password`).
/// This function will fail in case the password is not secure enough.
///
///
/// ```rust
/// # use rocket::{State, post};
/// # use rocket_auth::{Error, Users};
Expand Down Expand Up @@ -113,13 +113,13 @@ impl<'r> FromRequest<'r> for User {
let guard = request.guard().await;
let auth: Auth = match guard {
Success(auth) => auth,
Failure(x) => return Failure(x),
Error(x) => return Error(x),
Forward(x) => return Forward(x),
};
if let Some(user) = auth.get_user().await {
Outcome::Success(user)
} else {
Outcome::Failure((Status::Unauthorized, Error::UnauthorizedError))
Outcome::Error((Status::Unauthorized, crate::Error::UnauthorizedError))
}
}
}
Expand All @@ -132,20 +132,20 @@ impl<'r> FromRequest<'r> for AdminUser {
let guard = request.guard().await;
let auth: Auth = match guard {
Success(auth) => auth,
Failure(x) => return Failure(x),
Error(x) => return Error(x),
Forward(x) => return Forward(x),
};
if let Some(user) = auth.get_user().await {
if user.is_admin {
return Outcome::Success(AdminUser(user));
}
}
Outcome::Failure((Status::Unauthorized, Error::UnauthorizedError))
Outcome::Error((Status::Unauthorized, crate::Error::UnauthorizedError))
}
}

use std::ops::*;
use argon2::verify_encoded;
use std::ops::*;

impl Deref for AdminUser {
type Target = User;
Expand Down