forked from Chewing_Bever/rusty-bever
Added lifetime thingy
parent
b4fc6fe2c0
commit
a8cd8618a3
|
@ -9,10 +9,10 @@ use rocket::{
|
||||||
use sha2::Sha256;
|
use sha2::Sha256;
|
||||||
|
|
||||||
/// Extracts a "Authorization: Bearer" string from the headers.
|
/// Extracts a "Authorization: Bearer" string from the headers.
|
||||||
pub struct Bearer(String);
|
pub struct Bearer<'a>(&'a str);
|
||||||
|
|
||||||
#[rocket::async_trait]
|
#[rocket::async_trait]
|
||||||
impl<'r> FromRequest<'r> for Bearer
|
impl<'r> FromRequest<'r> for Bearer<'r>
|
||||||
{
|
{
|
||||||
type Error = rb::errors::RBError;
|
type Error = rb::errors::RBError;
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ impl<'r> FromRequest<'r> for Bearer
|
||||||
None => return Outcome::Forward(()),
|
None => return Outcome::Forward(()),
|
||||||
};
|
};
|
||||||
|
|
||||||
Outcome::Success(Self(auth_string.to_string()))
|
Outcome::Success(Self(auth_string))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,9 +104,10 @@ impl<'r> FromRequest<'r> for Admin
|
||||||
|
|
||||||
async fn from_request(req: &'r Request<'_>) -> Outcome<Self, Self::Error>
|
async fn from_request(req: &'r Request<'_>) -> Outcome<Self, Self::Error>
|
||||||
{
|
{
|
||||||
let user = try_outcome!(req.guard::<User>().await);
|
let user = try_outcome!(req.guard::<User>().await).0;
|
||||||
if user.0.admin {
|
|
||||||
Outcome::Success(Self(user.0))
|
if user.admin {
|
||||||
|
Outcome::Success(Self(user))
|
||||||
} else {
|
} else {
|
||||||
Outcome::Forward(())
|
Outcome::Forward(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue