2023-09-23 15:56:21 +00:00
|
|
|
use rocket::{http::Status, serde::json::Json};
|
|
|
|
|
2023-09-25 22:26:00 +00:00
|
|
|
use super::{json_result::JsonResult, session::request};
|
2023-09-23 15:56:21 +00:00
|
|
|
|
|
|
|
// Instead of requesting pages and managing session & cookies manually,
|
|
|
|
// create a wrapper that:
|
|
|
|
// - Checks if the session cookie is valid
|
|
|
|
// - If not, tries to login
|
|
|
|
// - Makes the request
|
|
|
|
// - Returns the html string, or an error
|
|
|
|
|
|
|
|
#[get("/classroom/users/<full_name>")]
|
|
|
|
pub async fn get_users(full_name: String) -> (Status, Json<JsonResult<()>>) {
|
2023-09-25 22:26:00 +00:00
|
|
|
let html = request(format!("/main/admin/user_list.php?keyword={}&submit=&_qf__search_simple=", full_name)).await;
|
|
|
|
|
|
|
|
match html {
|
|
|
|
Ok(html) => {
|
|
|
|
println!("{}", html);
|
|
|
|
(Status::Ok, JsonResult::ok(()))
|
|
|
|
}
|
|
|
|
Err(reason) => {
|
|
|
|
(Status::InternalServerError, JsonResult::err(reason))
|
|
|
|
}
|
|
|
|
}
|
2023-09-23 15:56:21 +00:00
|
|
|
}
|