Skip to content

Commit

Permalink
feat: cookie renew api
Browse files Browse the repository at this point in the history
  • Loading branch information
juliuskreutz committed Nov 15, 2024
1 parent 74dd8ff commit adae5da
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 18 deletions.
74 changes: 56 additions & 18 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/api/users/me/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ mod export;
mod gi;
mod import;
mod password;
mod renew;
mod uids;
mod username;
mod zzz;
Expand Down Expand Up @@ -35,6 +36,7 @@ pub fn openapi() -> utoipa::openapi::OpenApi {
openapi.merge(gi::openapi());
openapi.merge(import::openapi());
openapi.merge(password::openapi());
openapi.merge(renew::openapi());
openapi.merge(uids::openapi());
openapi.merge(username::openapi());
openapi.merge(zzz::openapi());
Expand All @@ -49,6 +51,7 @@ pub fn configure(cfg: &mut web::ServiceConfig) {
.configure(gi::configure)
.configure(import::configure)
.configure(password::configure)
.configure(renew::configure)
.configure(uids::configure)
.configure(username::configure)
.configure(zzz::configure);
Expand Down
40 changes: 40 additions & 0 deletions src/api/users/me/renew/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use actix_session::Session;
use actix_web::{post, web, HttpResponse, Responder};
use utoipa::OpenApi;

use crate::api::ApiResult;

#[derive(OpenApi)]
#[openapi(
tags((name = "users/me/renew")),
paths(post_renew)
)]
struct ApiDoc;

pub fn openapi() -> utoipa::openapi::OpenApi {
ApiDoc::openapi()
}

pub fn configure(cfg: &mut web::ServiceConfig) {
cfg.service(post_renew);
}

#[utoipa::path(
tag = "users/me/renew",
get,
path = "/api/users/me/renew",
responses(
(status = 200, description = "Successfully renewed", body = String),
(status = 400, description = "Not logged in"),
)
)]
#[post("/api/users/me/renew")]
async fn post_renew(session: Session) -> ApiResult<impl Responder> {
let Ok(Some(username)) = session.get::<String>("username") else {
return Ok(HttpResponse::BadRequest().finish());
};

session.renew();

Ok(HttpResponse::Ok().json(username))
}

0 comments on commit adae5da

Please sign in to comment.