Merge branch 'main' into feature/frontend-triptype
This commit is contained in:
commit
6fa43053ba
@ -29,6 +29,7 @@ pub enum LoginError {
|
|||||||
NotAnAdmin,
|
NotAnAdmin,
|
||||||
NotACox,
|
NotACox,
|
||||||
NoPasswordSet(User),
|
NoPasswordSet(User),
|
||||||
|
DeserializationError,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl User {
|
impl User {
|
||||||
@ -162,10 +163,12 @@ impl<'r> FromRequest<'r> for User {
|
|||||||
|
|
||||||
async fn from_request(req: &'r Request<'_>) -> request::Outcome<Self, Self::Error> {
|
async fn from_request(req: &'r Request<'_>) -> request::Outcome<Self, Self::Error> {
|
||||||
match req.cookies().get_private("loggedin_user") {
|
match req.cookies().get_private("loggedin_user") {
|
||||||
Some(user) => {
|
Some(user) => match serde_json::from_str(user.value()) {
|
||||||
let user: User = serde_json::from_str(user.value()).unwrap(); //TODO: fixme
|
Ok(user) => Outcome::Success(user),
|
||||||
Outcome::Success(user)
|
Err(_) => {
|
||||||
}
|
Outcome::Failure((Status::Unauthorized, LoginError::DeserializationError))
|
||||||
|
}
|
||||||
|
},
|
||||||
None => Outcome::Failure((Status::Unauthorized, LoginError::NotLoggedIn)),
|
None => Outcome::Failure((Status::Unauthorized, LoginError::NotLoggedIn)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -200,15 +203,13 @@ impl<'r> FromRequest<'r> for CoxUser {
|
|||||||
type Error = LoginError;
|
type Error = LoginError;
|
||||||
|
|
||||||
async fn from_request(req: &'r Request<'_>) -> request::Outcome<Self, Self::Error> {
|
async fn from_request(req: &'r Request<'_>) -> request::Outcome<Self, Self::Error> {
|
||||||
match req.cookies().get_private("loggedin_user") {
|
match User::from_request(req).await {
|
||||||
Some(user) => {
|
Outcome::Success(user) => match user.try_into() {
|
||||||
let user: User = serde_json::from_str(user.value()).unwrap(); //TODO: fixme
|
Ok(user) => Outcome::Success(user),
|
||||||
match user.try_into() {
|
Err(_) => Outcome::Failure((Status::Unauthorized, LoginError::NotACox)),
|
||||||
Ok(user) => Outcome::Success(user),
|
},
|
||||||
Err(_) => Outcome::Failure((Status::Unauthorized, LoginError::NotAnAdmin)),
|
Outcome::Failure(f) => Outcome::Failure(f),
|
||||||
}
|
Outcome::Forward(f) => Outcome::Forward(f),
|
||||||
}
|
|
||||||
None => Outcome::Failure((Status::Unauthorized, LoginError::NotLoggedIn)),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -235,15 +236,13 @@ impl<'r> FromRequest<'r> for AdminUser {
|
|||||||
type Error = LoginError;
|
type Error = LoginError;
|
||||||
|
|
||||||
async fn from_request(req: &'r Request<'_>) -> request::Outcome<Self, Self::Error> {
|
async fn from_request(req: &'r Request<'_>) -> request::Outcome<Self, Self::Error> {
|
||||||
match req.cookies().get_private("loggedin_user") {
|
match User::from_request(req).await {
|
||||||
Some(user) => {
|
Outcome::Success(user) => match user.try_into() {
|
||||||
let user: User = serde_json::from_str(user.value()).unwrap(); //TODO: fixme
|
Ok(user) => Outcome::Success(user),
|
||||||
match user.try_into() {
|
Err(_) => Outcome::Failure((Status::Unauthorized, LoginError::NotAnAdmin)),
|
||||||
Ok(user) => Outcome::Success(user),
|
},
|
||||||
Err(_) => Outcome::Failure((Status::Unauthorized, LoginError::NotAnAdmin)),
|
Outcome::Failure(f) => Outcome::Failure(f),
|
||||||
}
|
Outcome::Forward(f) => Outcome::Forward(f),
|
||||||
}
|
|
||||||
None => Outcome::Failure((Status::Unauthorized, LoginError::NotLoggedIn)),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user