add login confirmation

This commit is contained in:
Mylloon 2023-01-13 21:20:54 +01:00
parent c1925894f7
commit e7c9ddbedb
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
2 changed files with 25 additions and 22 deletions

View file

@ -1,16 +1,14 @@
use scraper::{Html, Selector};
use crate::utils::write_html;
/// Retrieves marks for a user
pub async fn get_marks(username: String, password: String, user_agent: &str) {
// Login
let client = login(username, password, user_agent).await.unwrap();
// Marks
let page = load_marks(&client).await.unwrap();
load_marks(&client).await.unwrap();
write_html(page.html());
println!("Notes *récupérés* !")
}
/// Login to eP8
@ -58,15 +56,27 @@ async fn login(
];
// Login
client
let sel_confirmation = Selector::parse("h2").unwrap();
if Html::parse_document(
&client
.post(login_url)
.form(&params)
.send()
.await?
.text()
.await?;
.await?,
)
.select(&sel_confirmation)
.next()
.unwrap()
.inner_html()
.contains("Connexion réussie")
{
println!("Connexion réussie...");
Ok(client)
} else {
panic!("Connexion échouée : Mauvais identifiants")
}
}
/// Load marks from scolarite-etudiant

View file

@ -19,19 +19,12 @@ pub fn ask_password() -> std::string::String {
rpassword::read_password().unwrap()
}
#[allow(dead_code)]
/// Write a document to a file
///
/// `html_data` may be created with something like that:
/// ```
/// Html::parse_document(
/// &client
/// .get("URL")
/// .send()
/// .await?
/// .text()
/// .await?,
/// )
/// .html(),
/// Html::parse_document(&client.get("URL").send().await?.text().await?).html()
/// ```
pub fn write_html(html_data: String) {
let mut f = std::fs::File::create("./target/temp.html").unwrap();