Log login html response
This commit is contained in:
parent
16bd38e6a7
commit
47f20b8920
@ -1,7 +1,7 @@
|
|||||||
use chrono::{DateTime, Local, TimeZone, Utc};
|
use chrono::{DateTime, Local, TimeZone, Utc};
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use urlencoding::encode;
|
|
||||||
use std::time::{SystemTime, UNIX_EPOCH};
|
use std::time::{SystemTime, UNIX_EPOCH};
|
||||||
|
use urlencoding::encode;
|
||||||
|
|
||||||
use isahc::{cookies::CookieJar, prelude::*, Request};
|
use isahc::{cookies::CookieJar, prelude::*, Request};
|
||||||
use std::sync::RwLock;
|
use std::sync::RwLock;
|
||||||
@ -106,7 +106,7 @@ pub async fn create_user_request(url: String, body: String) -> Result<String, St
|
|||||||
}
|
}
|
||||||
|
|
||||||
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,19 +134,7 @@ pub async fn register_courses_request(url: String, body: String) -> Result<Strin
|
|||||||
};
|
};
|
||||||
|
|
||||||
match response.text() {
|
match response.text() {
|
||||||
Ok(t) => {
|
Ok(t) => 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)
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(t)
|
|
||||||
},
|
|
||||||
Err(err) => Err(format!("Error getting text from response: {:?}", err)),
|
Err(err) => Err(format!("Error getting text from response: {:?}", err)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -196,10 +184,36 @@ async fn login() -> Result<(), String> {
|
|||||||
.send();
|
.send();
|
||||||
|
|
||||||
match response {
|
match response {
|
||||||
Ok(_) => {
|
Ok(mut r) => {
|
||||||
SESSION_COOKIE.write().unwrap().jar = jar.clone();
|
if r.status() == isahc::http::StatusCode::FOUND {
|
||||||
Ok(())
|
SESSION_COOKIE.write().unwrap().jar = jar.clone();
|
||||||
|
Ok(())
|
||||||
|
} else {
|
||||||
|
// Write html to file
|
||||||
|
match r.text() {
|
||||||
|
Ok(t) => {
|
||||||
|
log_html(t);
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
return Err(format!("Error getting text from login response: {:?}", err))
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Err(format!("Error connecting to online classroom: not 302"))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Err(error) => Err(format!("Error connecting to online classroom: {:?}", error)),
|
Err(error) => Err(format!("Error connecting to online classroom: {:?}", error)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
if let Err(err) = r {
|
||||||
|
eprintln!("Error writing request html to file: {:?}", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -6,30 +6,37 @@ import { LoadingStatus, backend, useLoading, wait } from "../utils/functions";
|
|||||||
import { LinkIcon } from "../icons/LinkIcon";
|
import { LinkIcon } from "../icons/LinkIcon";
|
||||||
import { For, Show, createSignal, onMount } from "solid-js";
|
import { For, Show, createSignal, onMount } from "solid-js";
|
||||||
import { LoadingIcon } from "../icons/LoadingIcon";
|
import { LoadingIcon } from "../icons/LoadingIcon";
|
||||||
|
import { AxiosError } from "axios";
|
||||||
|
|
||||||
type Status = "Init" | "Ok" | "Loading" | "Error";
|
|
||||||
export function ClassroomVinculation(props: {
|
export function ClassroomVinculation(props: {
|
||||||
person_surname: string,
|
person_surname: string,
|
||||||
personId: number,
|
personId: number,
|
||||||
onLink: (classroom_id: number, classroom_username: string) => void,
|
onLink: (classroom_id: number, classroom_username: string) => void,
|
||||||
}) {
|
}) {
|
||||||
const [classroomUsers, setClassroomUsers] = createSignal<ClassroomRegistrationUser[]>([]);
|
const [classroomUsers, setClassroomUsers] = createSignal<ClassroomRegistrationUser[]>([]);
|
||||||
const [error, setError] = createSignal("");
|
const {status, setStatus, error, setError} = useLoading();
|
||||||
const [status, setStatus] = createSignal<Status>("Init");
|
|
||||||
|
|
||||||
const loadUsers = async() => {
|
const loadUsers = async() => {
|
||||||
setStatus("Loading");
|
setClassroomUsers([]);
|
||||||
const response = await fetch(`${import.meta.env.VITE_BACKEND_URL}/api/classroom/users/${encodeURIComponent(props.person_surname)}`);
|
setStatus(LoadingStatus.Loading);
|
||||||
const json: JsonResult<Array<ClassroomRegistrationUser>> = await response.json();
|
|
||||||
|
|
||||||
if (response.ok) {
|
backend.get<JsonResult<Array<ClassroomRegistrationUser>>>(`/api/classroom/users/${encodeURIComponent(props.person_surname)}`)
|
||||||
setClassroomUsers(json.Ok);
|
.then((response) => {
|
||||||
setStatus("Ok");
|
if (response.status === 200) {
|
||||||
} else {
|
setClassroomUsers(response.data.Ok);
|
||||||
console.error("Error loading users", json);
|
setStatus(LoadingStatus.Ok);
|
||||||
setError(json.Err.reason);
|
} else {
|
||||||
setStatus("Error");
|
setClassroomUsers([]);
|
||||||
}
|
setStatus(LoadingStatus.Error);
|
||||||
|
console.error(response.data);
|
||||||
|
setError(response.data.Err.reason);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((err: AxiosError<JsonResult<Array<ClassroomRegistrationUser>>>) => {
|
||||||
|
console.error(err);
|
||||||
|
setError(`Error: ${err.response?.data.Err.reason ?? err.message}`);
|
||||||
|
setStatus(LoadingStatus.Error);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
onMount(loadUsers);
|
onMount(loadUsers);
|
||||||
@ -40,13 +47,13 @@ export function ClassroomVinculation(props: {
|
|||||||
Vincule un usuario existente:
|
Vincule un usuario existente:
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<Show when={status() === "Loading"}>
|
<Show when={status() === LoadingStatus.Loading}>
|
||||||
<div class="text-center h-12 scale-150">
|
<div class="text-center h-12 scale-150">
|
||||||
<LoadingIcon class="animate-spin" fill="var(--c-primary)" />
|
<LoadingIcon class="animate-spin" fill="var(--c-primary)" />
|
||||||
</div>
|
</div>
|
||||||
</Show>
|
</Show>
|
||||||
|
|
||||||
<Show when={status() === "Ok"}>
|
<Show when={status() === LoadingStatus.Ok}>
|
||||||
<Show when={classroomUsers().length === 0}>
|
<Show when={classroomUsers().length === 0}>
|
||||||
<div class="px-4 pb-2">
|
<div class="px-4 pb-2">
|
||||||
<div class="text-center pt-6 pb-4">
|
<div class="text-center pt-6 pb-4">
|
||||||
@ -66,7 +73,7 @@ export function ClassroomVinculation(props: {
|
|||||||
</For>
|
</For>
|
||||||
</Show>
|
</Show>
|
||||||
|
|
||||||
<Show when={status() === "Error"}>
|
<Show when={status() === LoadingStatus.Error}>
|
||||||
<div class="px-4 pb-2 text-c-error">
|
<div class="px-4 pb-2 text-c-error">
|
||||||
<div class="text-center pt-6 pb-4">
|
<div class="text-center pt-6 pb-4">
|
||||||
<XcircleIcon class="scale-[200%]" fill="var(--c-error)" />
|
<XcircleIcon class="scale-[200%]" fill="var(--c-error)" />
|
||||||
|
Loading…
Reference in New Issue
Block a user