mirror of
https://github.com/danbulant/Portfolio
synced 2026-06-19 22:41:13 +00:00
feat: candidate logout endpoint
This commit is contained in:
parent
8f282febc8
commit
35f591fb67
3 changed files with 19 additions and 0 deletions
|
|
@ -40,6 +40,7 @@ pub fn rocket() -> Rocket<Build>{
|
|||
"/candidate/",
|
||||
routes![
|
||||
routes::candidate::login,
|
||||
routes::candidate::logout,
|
||||
routes::candidate::whoami,
|
||||
routes::candidate::get_details,
|
||||
],
|
||||
|
|
|
|||
|
|
@ -51,6 +51,19 @@ pub async fn login(
|
|||
return Ok(response);
|
||||
}
|
||||
|
||||
#[post("/logout")]
|
||||
pub async fn logout(conn: Connection<'_, Db>, session: CandidateAuth, cookies: &CookieJar<'_>,) -> Result<(), Custom<String>> {
|
||||
let db = conn.into_inner();
|
||||
let candidate: entity::candidate::Model = session.into();
|
||||
|
||||
cookies.remove_private(Cookie::named("id"));
|
||||
cookies.remove_private(Cookie::named("key"));
|
||||
|
||||
CandidateService::logout(db, candidate.application)
|
||||
.await
|
||||
.map_err(|e| Custom(Status::from_code(e.code()).unwrap_or(Status::InternalServerError), e.to_string()))
|
||||
}
|
||||
|
||||
#[get("/whoami")]
|
||||
pub async fn whoami(session: CandidateAuth) -> Result<String, Custom<String>> {
|
||||
let candidate: entity::candidate::Model = session.into();
|
||||
|
|
|
|||
|
|
@ -131,6 +131,11 @@ impl CandidateService {
|
|||
Ok(new_password_plain)
|
||||
}
|
||||
|
||||
pub async fn logout(db: &DbConn, id: i32) -> Result<(), ServiceError> {
|
||||
SessionService::revoke_all_sessions(db, Some(id), None).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(in crate::services) async fn add_candidate_details(
|
||||
db: &DbConn,
|
||||
candidate: candidate::Model,
|
||||
|
|
|
|||
Loading…
Reference in a new issue