add login confirmation
This commit is contained in:
parent
c1925894f7
commit
e7c9ddbedb
2 changed files with 25 additions and 22 deletions
36
src/marks.rs
36
src/marks.rs
|
@ -1,16 +1,14 @@
|
||||||
use scraper::{Html, Selector};
|
use scraper::{Html, Selector};
|
||||||
|
|
||||||
use crate::utils::write_html;
|
|
||||||
|
|
||||||
/// Retrieves marks for a user
|
/// Retrieves marks for a user
|
||||||
pub async fn get_marks(username: String, password: String, user_agent: &str) {
|
pub async fn get_marks(username: String, password: String, user_agent: &str) {
|
||||||
// Login
|
// Login
|
||||||
let client = login(username, password, user_agent).await.unwrap();
|
let client = login(username, password, user_agent).await.unwrap();
|
||||||
|
|
||||||
// Marks
|
// 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
|
/// Login to eP8
|
||||||
|
@ -58,15 +56,27 @@ async fn login(
|
||||||
];
|
];
|
||||||
|
|
||||||
// Login
|
// Login
|
||||||
client
|
let sel_confirmation = Selector::parse("h2").unwrap();
|
||||||
.post(login_url)
|
if Html::parse_document(
|
||||||
.form(¶ms)
|
&client
|
||||||
.send()
|
.post(login_url)
|
||||||
.await?
|
.form(¶ms)
|
||||||
.text()
|
.send()
|
||||||
.await?;
|
.await?
|
||||||
|
.text()
|
||||||
Ok(client)
|
.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
|
/// 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()
|
rpassword::read_password().unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
/// Write a document to a file
|
/// Write a document to a file
|
||||||
///
|
///
|
||||||
/// `html_data` may be created with something like that:
|
/// `html_data` may be created with something like that:
|
||||||
/// ```
|
/// ```
|
||||||
/// Html::parse_document(
|
/// Html::parse_document(&client.get("URL").send().await?.text().await?).html()
|
||||||
/// &client
|
|
||||||
/// .get("URL")
|
|
||||||
/// .send()
|
|
||||||
/// .await?
|
|
||||||
/// .text()
|
|
||||||
/// .await?,
|
|
||||||
/// )
|
|
||||||
/// .html(),
|
|
||||||
/// ```
|
/// ```
|
||||||
pub fn write_html(html_data: String) {
|
pub fn write_html(html_data: String) {
|
||||||
let mut f = std::fs::File::create("./target/temp.html").unwrap();
|
let mut f = std::fs::File::create("./target/temp.html").unwrap();
|
||||||
|
|
Reference in a new issue