mirror of
https://github.com/danbulant/Portfolio
synced 2026-05-21 05:18:44 +00:00
fix: remove unused file
This commit is contained in:
parent
e2a9925b9b
commit
fc504efd58
1 changed files with 0 additions and 71 deletions
|
|
@ -1,71 +0,0 @@
|
|||
use entity::candidate::Model as Candidate;
|
||||
use portfolio_core::sea_orm::prelude::Uuid;
|
||||
use portfolio_core::services::admin_service::AdminService;
|
||||
use portfolio_core::services::candidate_service::CandidateService;
|
||||
use rocket::http::Status;
|
||||
use rocket::outcome::Outcome;
|
||||
use rocket::request::{FromRequest, Request};
|
||||
|
||||
use crate::pool::Db;
|
||||
|
||||
pub struct CandidateAuth(Candidate);
|
||||
|
||||
impl Into<Candidate> for CandidateAuth {
|
||||
fn into(self) -> Candidate {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
#[rocket::async_trait]
|
||||
impl<'r> FromRequest<'r> for CandidateAuth {
|
||||
type Error = Option<String>;
|
||||
async fn from_request(req: &'r Request<'_>) -> Outcome<CandidateAuth, (Status, Self::Error), ()> {
|
||||
let session_id = req.cookies().get("id").unwrap().name_value().1;
|
||||
let conn = &req.rocket().state::<Db>().unwrap().conn;
|
||||
|
||||
let uuid = match Uuid::parse_str(&session_id) {
|
||||
Ok(uuid) => uuid,
|
||||
Err(_) => return Outcome::Failure((Status::BadRequest, None)),
|
||||
};
|
||||
|
||||
let session = CandidateService::auth(conn, uuid).await;
|
||||
|
||||
match session {
|
||||
Ok(model) => Outcome::Success(CandidateAuth(model)),
|
||||
Err(_) => Outcome::Failure((Status::Unauthorized, None)),
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
pub struct AdminAuth(Candidate);
|
||||
|
||||
impl Into<Candidate> for AdminAuth {
|
||||
fn into(self) -> Candidate {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
#[rocket::async_trait]
|
||||
impl<'r> FromRequest<'r> for AdminAuth {
|
||||
type Error = Option<String>;
|
||||
async fn from_request(req: &'r Request<'_>) -> Outcome<AdminAuth, (Status, Self::Error), ()> {
|
||||
let session_id = req.cookies().get("id").unwrap().name_value().1;
|
||||
let conn = &req.rocket().state::<Db>().unwrap().conn;
|
||||
|
||||
let uuid = match Uuid::parse_str(&session_id) {
|
||||
Ok(uuid) => uuid,
|
||||
Err(_) => return Outcome::Failure((Status::BadRequest, None)),
|
||||
};
|
||||
|
||||
let session = AdminService::auth(conn, uuid).await;
|
||||
|
||||
match session {
|
||||
Ok(model) => Outcome::Success(AdminAuth(model)),
|
||||
Err(e) => Outcome::Failure(
|
||||
(Status::from_code(e.code()).unwrap_or(Status::InternalServerError), None)
|
||||
),
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue