deduplicate code
This commit is contained in:
parent
0b34b776ac
commit
3f01bf39b3
@ -203,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
|
|
||||||
match user.try_into() {
|
|
||||||
Ok(user) => Outcome::Success(user),
|
Ok(user) => Outcome::Success(user),
|
||||||
Err(_) => Outcome::Failure((Status::Unauthorized, LoginError::NotAnAdmin)),
|
Err(_) => Outcome::Failure((Status::Unauthorized, LoginError::NotACox)),
|
||||||
}
|
},
|
||||||
}
|
Outcome::Failure(f) => Outcome::Failure(f),
|
||||||
None => Outcome::Failure((Status::Unauthorized, LoginError::NotLoggedIn)),
|
Outcome::Forward(f) => Outcome::Forward(f),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -238,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
|
|
||||||
match user.try_into() {
|
|
||||||
Ok(user) => Outcome::Success(user),
|
Ok(user) => Outcome::Success(user),
|
||||||
Err(_) => Outcome::Failure((Status::Unauthorized, LoginError::NotAnAdmin)),
|
Err(_) => Outcome::Failure((Status::Unauthorized, LoginError::NotAnAdmin)),
|
||||||
}
|
},
|
||||||
}
|
Outcome::Failure(f) => Outcome::Failure(f),
|
||||||
None => Outcome::Failure((Status::Unauthorized, LoginError::NotLoggedIn)),
|
Outcome::Forward(f) => Outcome::Forward(f),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user