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() {
|
match response.text() {
|
||||||
Ok(t) => {
|
Ok(t) => {
|
||||||
// Get current time and date in iso
|
log_html(&t);
|
||||||
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)
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(t)
|
Ok(t)
|
||||||
}
|
}
|
||||||
Err(err) => Err(format!("Error getting text from response: {:?}", err)),
|
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() {
|
match response.text() {
|
||||||
Ok(t) => {
|
Ok(t) => {
|
||||||
// Get current time and date in iso
|
log_html(&t);
|
||||||
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)
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(t)
|
Ok(t)
|
||||||
}
|
}
|
||||||
Err(err) => Err(format!("Error getting text from response: {:?}", err)),
|
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() {
|
match response.text() {
|
||||||
Ok(t) => Ok(t),
|
Ok(t) => {
|
||||||
|
log_html(&t);
|
||||||
|
Ok(t)
|
||||||
|
},
|
||||||
Err(err) => Err(format!("Error getting text from response: {:?}", err)),
|
Err(err) => Err(format!("Error getting text from response: {:?}", err)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -172,27 +157,31 @@ async fn login() -> Result<(), String> {
|
|||||||
|
|
||||||
let jar = CookieJar::new();
|
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))
|
let response = Request::post(format!("{}/index.php", classroom_url))
|
||||||
.header("Content-Type", "application/x-www-form-urlencoded")
|
.header("Content-Type", "application/x-www-form-urlencoded")
|
||||||
.cookie_jar(jar.clone())
|
.cookie_jar(jar.clone())
|
||||||
.body(format!(
|
.body(login_body)
|
||||||
"login={}&password={}&submitAuth=&_qf__formLogin=",
|
|
||||||
encode(classroom_user.as_str()),
|
|
||||||
encode(classroom_password.as_str()),
|
|
||||||
))
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.send();
|
.send();
|
||||||
|
|
||||||
match response {
|
match response {
|
||||||
Ok(mut r) => {
|
Ok(mut r) => {
|
||||||
if r.status() == isahc::http::StatusCode::FOUND {
|
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();
|
SESSION_COOKIE.write().unwrap().jar = jar.clone();
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
// Write html to file
|
// Write html to file
|
||||||
match r.text() {
|
match r.text() {
|
||||||
Ok(t) => {
|
Ok(t) => {
|
||||||
log_html(t);
|
log_html(&t);
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
return Err(format!("Error getting text from login response: {:?}", 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
|
// Get current time and date in iso
|
||||||
let now: DateTime<Local> = Local::now();
|
let now: DateTime<Local> = Local::now();
|
||||||
let now = now.to_rfc3339();
|
let now = now.to_rfc3339();
|
||||||
|
|
||||||
// Write html to file
|
// 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 {
|
if let Err(err) = r {
|
||||||
eprintln!("Error writing request html to file: {:?}", err)
|
eprintln!("Error writing request html to file: {:?}", err)
|
||||||
}
|
}
|
||||||
|
@ -29,12 +29,12 @@ export function ClassroomVinculation(props: {
|
|||||||
setClassroomUsers([]);
|
setClassroomUsers([]);
|
||||||
setStatus(LoadingStatus.Error);
|
setStatus(LoadingStatus.Error);
|
||||||
console.error(response.data);
|
console.error(response.data);
|
||||||
setError(response.data.Err.reason);
|
setError(response.data.Error.reason);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((err: AxiosError<JsonResult<Array<ClassroomRegistrationUser>>>) => {
|
.catch((err: AxiosError<JsonResult<Array<ClassroomRegistrationUser>>>) => {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
setError(`Error: ${err.response?.data.Err.reason ?? err.message}`);
|
setError(`Error: ${err.response?.data?.Error?.reason ?? err.message}`);
|
||||||
setStatus(LoadingStatus.Error);
|
setStatus(LoadingStatus.Error);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -112,9 +112,9 @@ function ClassroomSingleUser(props: {
|
|||||||
setStatus(LoadingStatus.Ok);
|
setStatus(LoadingStatus.Ok);
|
||||||
props.onLink(parseInt(props.user.user_id, 10), props.user.username);
|
props.onLink(parseInt(props.user.user_id, 10), props.user.username);
|
||||||
} else {
|
} else {
|
||||||
console.error(response.data);
|
|
||||||
setError(response.data.Err.reason);
|
|
||||||
setStatus(LoadingStatus.Error);
|
setStatus(LoadingStatus.Error);
|
||||||
|
console.error(response.data);
|
||||||
|
setError(response.data.Error.reason);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
export type JsonResult<T> = {
|
export type JsonResult<T> = {
|
||||||
Ok: T,
|
Ok: T,
|
||||||
Err: {
|
Error: {
|
||||||
reason: string
|
reason: string
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user