Refactoring of frontend and OIDC

I want to make some code reusable for other projects
This commit is contained in:
Lennart
2025-04-20 21:23:52 +02:00
parent 678d2291e0
commit 2c74d56f50
6 changed files with 109 additions and 87 deletions

View File

@@ -18,7 +18,7 @@ pub async fn route_calendar<C: CalendarStore>(
store: Data<C>,
user: User,
req: HttpRequest,
) -> Result<impl Responder, rustical_store::Error> {
) -> Result<HttpResponse, rustical_store::Error> {
let (owner, cal_id) = path.into_inner();
if !user.is_principal(&owner) {
return Ok(HttpResponse::Unauthorized().body("Unauthorized"));
@@ -34,7 +34,7 @@ pub async fn route_calendar_restore<CS: CalendarStore>(
req: HttpRequest,
store: Data<CS>,
user: User,
) -> Result<impl Responder, rustical_store::Error> {
) -> Result<HttpResponse, rustical_store::Error> {
let (owner, cal_id) = path.into_inner();
if !user.is_principal(&owner) {
return Ok(HttpResponse::Unauthorized().body("Unauthorized"));
@@ -45,6 +45,6 @@ pub async fn route_calendar_restore<CS: CalendarStore>(
.using_status_code(StatusCode::FOUND)
.respond_to(&req)
.map_into_boxed_body(),
None => HttpResponse::Ok().body("Restored"),
None => HttpResponse::Created().body("Restored"),
})
}

View File

@@ -1,4 +1,4 @@
use crate::{FrontendConfig, OidcConfig, oidc::OidcProviderData};
use crate::{FrontendConfig, OidcConfig, oidc::ROUTE_NAME_OIDC_LOGIN};
use actix_session::Session;
use actix_web::{
HttpRequest, HttpResponse, Responder,
@@ -19,6 +19,11 @@ struct LoginPage<'a> {
allow_password_login: bool,
}
struct OidcProviderData<'a> {
pub name: &'a str,
pub redirect_url: String,
}
#[derive(Debug, Deserialize)]
pub struct GetLoginQuery {
redirect_uri: Option<String>,
@@ -30,14 +35,14 @@ pub async fn route_get_login(
req: HttpRequest,
config: Data<FrontendConfig>,
oidc_config: Data<Option<OidcConfig>>,
) -> impl Responder {
) -> HttpResponse {
let oidc_data = oidc_config
.as_ref()
.as_ref()
.map(|oidc_config| OidcProviderData {
name: &oidc_config.name,
redirect_url: req
.url_for_static("frontend_login_oidc")
.url_for_static(ROUTE_NAME_OIDC_LOGIN)
.unwrap()
.to_string(),
});