add login confirmation
This commit is contained in:
parent
c1925894f7
commit
e7c9ddbedb
2 changed files with 25 additions and 22 deletions
24
src/marks.rs
24
src/marks.rs
|
@ -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(¶ms)
|
||||
.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
|
||||
|
|
11
src/utils.rs
11
src/utils.rs
|
@ -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();
|
||||
|
|
Reference in a new issue