summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSanto Cariotti <santo@dcariotti.me>2021-09-29 22:34:26 +0200
committerSanto Cariotti <santo@dcariotti.me>2021-09-29 22:42:03 +0200
commit9f6d275620e29295a41bcca342ee0da531664721 (patch)
tree8111a0ece8be646a6686eebdc9d067a3209d14c2
parent8de625e9eba926c7ca8c2f86d658283480938b2f (diff)
chore: save crendetials into the browser struct
-rw-r--r--src/browser/mod.rs4
-rw-r--r--src/browser/web_browser.rs17
-rw-r--r--src/main.rs2
3 files changed, 18 insertions, 5 deletions
diff --git a/src/browser/mod.rs b/src/browser/mod.rs
index 528849d..9b36c94 100644
--- a/src/browser/mod.rs
+++ b/src/browser/mod.rs
@@ -8,9 +8,9 @@ mod web_browser;
/// Create a new instance of `Browser` and associate it with the static variable `WEB_BROWSER`.
/// This is an unsecure type of usage, so the block is inside the `unsafe` block
-pub async fn init(driver_url: &String) {
+pub async fn init(config: &Config) {
unsafe {
- WEB_BROWSER = Some(Browser::new(driver_url).await);
+ WEB_BROWSER = Some(Browser::new(config).await);
}
}
diff --git a/src/browser/web_browser.rs b/src/browser/web_browser.rs
index 59b2dff..d014bd6 100644
--- a/src/browser/web_browser.rs
+++ b/src/browser/web_browser.rs
@@ -11,15 +11,22 @@ const LOGIN_URL: &str = "https://studenti.smartedu.unict.it/WorkFlow2011/Logon/L
/// This url is used to go to the page where a student can book a room for study
pub const ROOMS_URL: &str = "https://studenti.smartedu.unict.it/StudentSpaceReserv?Type=unaTantum";
+#[derive(Debug)]
+struct Credentials {
+ cf: String,
+ password: String,
+}
+
/// Browser struct
pub struct Browser {
/// The driver for Firefox, it could be `None`
driver: Option<WebDriver>,
+ credentials: Credentials,
}
impl Browser {
/// Create a new `Browser` with a Firefox driver with a personalized User-Agent
- pub async fn new(driver_url: &String) -> Self {
+ pub async fn new(config: &Config) -> Self {
let user_agent =
"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:90.0) Gecko/20100101 Firefox/90.0";
@@ -30,8 +37,14 @@ impl Browser {
let _ = caps.set_preferences(prefs);
let _ = caps.set_headless();
+ let credentials = Credentials {
+ cf: config.cf.clone(),
+ password: config.password.clone(),
+ };
+
Self {
- driver: Some(WebDriver::new(driver_url, caps).await.unwrap()),
+ driver: Some(WebDriver::new(&config.driver_url, caps).await.unwrap()),
+ credentials,
}
}
diff --git a/src/main.rs b/src/main.rs
index 6b85559..136db38 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -20,7 +20,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
unsafe {
// Open the browser
- browser::init(&config.driver_url).await;
+ browser::init(&config).await;
// Login using the credentials inside the `config`
match browser::login(&config).await {