From 0059dfe96ff6227bbf29acfa71bab90efe3887f0 Mon Sep 17 00:00:00 2001 From: Philipp Hofer Date: Fri, 18 Apr 2025 17:04:10 +0200 Subject: [PATCH] simple nx auth --- src/tera/mod.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/tera/mod.rs b/src/tera/mod.rs index ac3a130..91f6ecb 100644 --- a/src/tera/mod.rs +++ b/src/tera/mod.rs @@ -123,6 +123,19 @@ async fn wikiauth(db: &State, login: Form>) -> String "FAIL".into() } +#[post("/", data = "")] +async fn nextcloud_auth(db: &State, login: Form>) -> String { + if let Ok(user) = User::login(db, login.name, login.password).await { + if user.has_role(db, "admin").await { + return String::from("SUCC"); + } + if user.has_role(db, "Vorstand").await { + return String::from("SUCC"); + } + } + "FAIL".into() +} + #[catch(401)] //Unauthorized fn unauthorized_error(req: &Request) -> Redirect { // Save the URL the user tried to access, to be able to go there once logged in @@ -264,6 +277,7 @@ pub fn config(rocket: Rocket) -> Rocket { .mount("/", routes![index, steering, impressum]) .mount("/auth", auth::routes()) .mount("/wikiauth", routes![wikiauth]) + .mount("/nxauth", routes![nextcloud_auth]) .mount("/new-blogpost", routes![new_blogpost]) .mount("/blogpost-unpublished", routes![blogpost_unpublished]) .mount("/log", log::routes()) -- 2.47.2