Bläddra i källkod

Add redirect for /:realm/um -> /:realm/um/

Kestrel 11 månader sedan
förälder
incheckning
a2cb90fdb0
2 ändrade filer med 10 tillägg och 7 borttagningar
  1. 3 2
      src/server.rs
  2. 7 5
      src/server/um.rs

+ 3 - 2
src/server.rs

@@ -31,7 +31,8 @@ async fn index(req: tide::Request<ServerStateWrapper>) -> tide::Result<tide::Res
             realm: {realm:?}
             session: {session:?}
             auth: {auth:?}
-        "#
+            um link: {link}
+            "#, link = req.url().join("um/").unwrap()
         ))
         .build();
     Ok(response)
@@ -73,7 +74,7 @@ pub async fn run_server(
 
     session::session_v1_server(app.at("/:realm/v1/session/"));
     oidc::oidc_server(app.at("/:realm/"));
-    um::um_server(app.at("/:realm/um/"));
+    um::um_server(app.at("/:realm/"));
 
     app.listen(("127.0.0.1", port))
         .await

+ 7 - 5
src/server/um.rs

@@ -9,8 +9,7 @@ fn generate_template_data(
     realm: &microrm::Stored<schema::Realm>,
     user: &microrm::Stored<schema::User>,
 ) -> Result<serde_json::Value, UIDCError> {
-    let totp : microrm::Serialized<_> = schema::AuthChallengeType::TOTP.into();
-    let has_totp = user.auth.with(schema::AuthChallenge::ChallengeType, totp).count()? > 0;
+    let has_totp = user.auth.with(schema::AuthChallenge::ChallengeType, schema::AuthChallengeType::TOTP.into_serialized()).count()? > 0;
 
     let template_data = serde_json::json!({
         "username": user.username,
@@ -113,7 +112,7 @@ async fn um_update(mut req: Request) -> tide::Result<tide::Response> {
                 info_msgs.push("Cleared TOTP setup".into());
             } else if totp == "reset" {
                 let (_secret, _uri) = user.generate_totp_with_uri()?;
-                Err(UIDCError::Abort("totp setup outside of cli not supported"))?
+                Err(UIDCError::Abort("totp setup outside of cli not (yet) supported"))?
             }
         }
 
@@ -153,7 +152,10 @@ async fn um_update(mut req: Request) -> tide::Result<tide::Response> {
 }
 
 pub(super) fn um_server(mut route: tide::Route<super::ServerStateWrapper>) {
-    route.at("/").get(um_index);
-    route.at("update").post(um_update);
+    route.at("um").get(|_req| async {
+        Ok(tide::Redirect::permanent("um/"))
+    });
+    route.at("um/").get(um_index);
+    route.at("um/update").post(um_update);
     // route.at("/change_password").get(um_change_password).post(um_change_password_post);
 }