Bug fixes
This commit is contained in:
parent
47f20b8920
commit
595e2debea
@ -42,16 +42,7 @@ pub async fn request(url: String) -> Result<String, String> {
|
||||
|
||||
match response.text() {
|
||||
Ok(t) => {
|
||||
// Get current time and date in iso
|
||||
let now: DateTime<Local> = Local::now();
|
||||
let now = now.to_rfc3339();
|
||||
|
||||
// Write html to file
|
||||
let r = std::fs::write(format!("request-logs/{}.html", now), &t);
|
||||
if let Err(err) = r {
|
||||
eprintln!("Error writing request html to file: {:?}", err)
|
||||
}
|
||||
|
||||
log_html(&t);
|
||||
Ok(t)
|
||||
}
|
||||
Err(err) => Err(format!("Error getting text from response: {:?}", err)),
|
||||
@ -95,16 +86,7 @@ pub async fn create_user_request(url: String, body: String) -> Result<String, St
|
||||
|
||||
match response.text() {
|
||||
Ok(t) => {
|
||||
// Get current time and date in iso
|
||||
let now: DateTime<Local> = Local::now();
|
||||
let now = now.to_rfc3339();
|
||||
|
||||
// Write html to file
|
||||
let r = std::fs::write(format!("request-logs/{}.html", now), &t);
|
||||
if let Err(err) = r {
|
||||
eprintln!("Error writing request html to file: {:?}", err)
|
||||
}
|
||||
|
||||
log_html(&t);
|
||||
Ok(t)
|
||||
}
|
||||
Err(err) => Err(format!("Error getting text from response: {:?}", err)),
|
||||
@ -134,7 +116,10 @@ pub async fn register_courses_request(url: String, body: String) -> Result<Strin
|
||||
};
|
||||
|
||||
match response.text() {
|
||||
Ok(t) => Ok(t),
|
||||
Ok(t) => {
|
||||
log_html(&t);
|
||||
Ok(t)
|
||||
},
|
||||
Err(err) => Err(format!("Error getting text from response: {:?}", err)),
|
||||
}
|
||||
}
|
||||
@ -172,27 +157,31 @@ async fn login() -> Result<(), String> {
|
||||
|
||||
let jar = CookieJar::new();
|
||||
|
||||
let login_body = format!(
|
||||
"login={}&password={}&submitAuth=&_qf__formLogin=",
|
||||
encode(classroom_user.as_str()).into_owned(),
|
||||
encode(classroom_password.as_str()).into_owned(),
|
||||
);
|
||||
|
||||
let response = Request::post(format!("{}/index.php", classroom_url))
|
||||
.header("Content-Type", "application/x-www-form-urlencoded")
|
||||
.cookie_jar(jar.clone())
|
||||
.body(format!(
|
||||
"login={}&password={}&submitAuth=&_qf__formLogin=",
|
||||
encode(classroom_user.as_str()),
|
||||
encode(classroom_password.as_str()),
|
||||
))
|
||||
.body(login_body)
|
||||
.unwrap()
|
||||
.send();
|
||||
|
||||
match response {
|
||||
Ok(mut r) => {
|
||||
if r.status() == isahc::http::StatusCode::FOUND {
|
||||
// TODO: Even if this is a 302, it might not be a successful login
|
||||
// check Set-Cookie header
|
||||
SESSION_COOKIE.write().unwrap().jar = jar.clone();
|
||||
Ok(())
|
||||
} else {
|
||||
// Write html to file
|
||||
match r.text() {
|
||||
Ok(t) => {
|
||||
log_html(t);
|
||||
log_html(&t);
|
||||
}
|
||||
Err(err) => {
|
||||
return Err(format!("Error getting text from login response: {:?}", err))
|
||||
@ -206,13 +195,13 @@ async fn login() -> Result<(), String> {
|
||||
}
|
||||
}
|
||||
|
||||
fn log_html(html: String) {
|
||||
fn log_html(html: &String) {
|
||||
// Get current time and date in iso
|
||||
let now: DateTime<Local> = Local::now();
|
||||
let now = now.to_rfc3339();
|
||||
|
||||
// Write html to file
|
||||
let r = std::fs::write(format!("request-logs/{}.html", now), &html);
|
||||
let r = std::fs::write(format!("request-logs/{}.html", now), html);
|
||||
if let Err(err) = r {
|
||||
eprintln!("Error writing request html to file: {:?}", err)
|
||||
}
|
||||
|
@ -29,12 +29,12 @@ export function ClassroomVinculation(props: {
|
||||
setClassroomUsers([]);
|
||||
setStatus(LoadingStatus.Error);
|
||||
console.error(response.data);
|
||||
setError(response.data.Err.reason);
|
||||
setError(response.data.Error.reason);
|
||||
}
|
||||
})
|
||||
.catch((err: AxiosError<JsonResult<Array<ClassroomRegistrationUser>>>) => {
|
||||
console.error(err);
|
||||
setError(`Error: ${err.response?.data.Err.reason ?? err.message}`);
|
||||
setError(`Error: ${err.response?.data?.Error?.reason ?? err.message}`);
|
||||
setStatus(LoadingStatus.Error);
|
||||
});
|
||||
};
|
||||
@ -112,9 +112,9 @@ function ClassroomSingleUser(props: {
|
||||
setStatus(LoadingStatus.Ok);
|
||||
props.onLink(parseInt(props.user.user_id, 10), props.user.username);
|
||||
} else {
|
||||
console.error(response.data);
|
||||
setError(response.data.Err.reason);
|
||||
setStatus(LoadingStatus.Error);
|
||||
console.error(response.data);
|
||||
setError(response.data.Error.reason);
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
|
@ -1,6 +1,6 @@
|
||||
export type JsonResult<T> = {
|
||||
Ok: T,
|
||||
Err: {
|
||||
Error: {
|
||||
reason: string
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user