Parcourir la source

Minor cleanups.

Kestrel il y a 2 ans
Parent
commit
a35d0e238c
1 fichiers modifiés avec 0 ajouts et 73 suppressions
  1. 0 73
      src/server/identity.rs

+ 0 - 73
src/server/identity.rs

@@ -44,8 +44,6 @@ impl ServerState {
             .expose();
         let session_id = base64::encode_config(session_id, base64::URL_SAFE_NO_PAD);
 
-        // response.insert_cookie(Cookie::new("vogt_session", session_id.clone()));
-
         let maybe_id = qi.add(&crate::schema::Session { key: session_id.clone() });
         Ok((maybe_id.ok_or(tide::Error::from_str(
             500,
@@ -54,19 +52,14 @@ impl ServerState {
     }
 
     pub fn get_or_build_session(&self, req: &Request) -> tide::Result<(schema::SessionID, Option<tide::http::Cookie<'static>>)> {
-        println!("get_or_build_session()...");
         let qi = self.core.pool.query_interface();
         if let Some(sid) = req.cookie("vogt_session") {
-            println!("cookie is set ...");
             let existing = qi.get_one_by(schema::SessionColumns::Key, sid.value());
 
             if existing.is_some() {
-                println!("recognize the session!");
                 return Ok((existing.unwrap().id(), None))
             }
-            println!("don't recognize the session {}", sid.value());
         }
-        println!("building new session!");
         Self::build_session(qi)
     }
 
@@ -85,52 +78,6 @@ impl ServerState {
     }
 }
 
-async fn v1_check(req: Request) -> tide::Result<tide::Response> {
-    let validity = super::is_auth_valid(req.state().core, &req);
-    if let Some(true) = validity {
-        return Ok(tide::Response::builder(200).build());
-    } else if let Some(false) = validity {
-        return Ok(tide::Response::builder(403).build());
-    } else {
-        return Ok(tide::Response::builder(401).build());
-    }
-}
-
-
-/*
-fn get_session_auth(req: &tide::Request<ServerState>, response: &mut tide::Response) -> Option<microrm::WithID<schema::SessionAuthentication>> {
-    let qi = req.state().core.pool.query_interface();
-    let realm_name = req
-        .param("realm")
-        .expect("Failed to parse realm out of path?");
-
-    let sid: schema::SessionID = match req.cookie("vogt_session") {
-        Some(sid) => {
-            let existing = qi.get_one_by(schema::SessionColumns::Key, sid.value());
-
-            if let Some(id) = existing {
-                id.id()
-            } else {
-                build_session(&qi, response).ok()?
-            }
-        }
-        None => build_session(&qi, response).ok()?,
-    };
-
-    let realm_id = qi.get_one_by(schema::RealmColumns::Shortname, realm_name)?;
-
-    let realm_auth = qi.get_one_by_multi(
-        &[
-            schema::SessionAuthenticationColumns::Session,
-            schema::SessionAuthenticationColumns::Realm,
-        ],
-        &microrm::value_list!(&sid, &realm_id.id()),
-    );
-
-    realm_auth
-}
-*/
-
 impl ServerState {
     fn render_login_from_auth(&self, response: tide::Response, auth: Option<schema::SessionAuthentication>, error_msg: Option<String>) -> tide::Response {
         let to_present: Option<schema::AuthChallengeType> = match auth {
@@ -185,8 +132,6 @@ impl ServerState {
 async fn v1_login(req: tide::Request<ServerState>) -> tide::Result<tide::Response> {
     let mut response = tide::Response::builder(200).build();
 
-    // let qi = req.state().core.pool.query_interface();
-
     let realm = req.state().get_realm(&req).ok_or(tide::Error::from_str(404, "No such realm"))?;
     let (session_id, cookie) = req.state().get_or_build_session(&req)?;
     cookie.map(|c| response.insert_cookie(c));
@@ -194,21 +139,6 @@ async fn v1_login(req: tide::Request<ServerState>) -> tide::Result<tide::Respons
     let auth = req.state().get_auth_for_session(realm, session_id);
 
     Ok(req.state().render_login_from_auth(response, auth.map(|a| a.wrapped()), None))
-
-    /*let realm_auth = get_session_auth(&req, &mut response);
-
-    let to_present: Option<schema::AuthChallengeType> = match realm_auth {
-        None => Some(schema::AuthChallengeType::Username),
-        Some(auth) => auth.challenges_left.first().map(|x| *x),
-    };
-
-    if to_present.is_some() {
-        Ok(render_login_page(req.state(), response, to_present.unwrap(), None))
-    }
-    else {
-        // already logged in...
-        todo!()
-    }*/
 }
 
 async fn v1_login_response(mut req: tide::Request<ServerState>) -> tide::Result<tide::Response> {
@@ -264,8 +194,6 @@ async fn v1_login_response(mut req: tide::Request<ServerState>) -> tide::Result<
                 let id = qi.add(&sa).unwrap();
                 auth = Some(microrm::WithID::new(sa, id));
             }
-            // req.state().destroy_auth(realm, session_id);
-
         },
         ChallengeType::Password => {
             if auth.is_none() {
@@ -305,7 +233,6 @@ pub fn id_v1_server(core: &'static super::ServerCoreState) -> tide::Server<Serve
     srv.with(tide::log::LogMiddleware::new());
 
     srv.at("login").get(v1_login).post(v1_login_response);
-    srv.at("check").get(v1_check).head(v1_check);
 
     srv
 }