Prompt user for username and password

This commit is contained in:
FliegendeWurst 2020-04-21 23:12:05 +02:00
parent f10bba3e3e
commit e424ff6a72
3 changed files with 25 additions and 2 deletions

18
Cargo.lock generated
View File

@ -10,6 +10,8 @@ dependencies = [
"parking_lot", "parking_lot",
"regex", "regex",
"reqwest", "reqwest",
"rpassword",
"rprompt",
"scraper", "scraper",
"serde_json", "serde_json",
"structopt", "structopt",
@ -1243,6 +1245,22 @@ dependencies = [
"winreg", "winreg",
] ]
[[package]]
name = "rpassword"
version = "4.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "99371657d3c8e4d816fb6221db98fa408242b0b53bac08f8676a41f8554fe99f"
dependencies = [
"libc",
"winapi 0.3.8",
]
[[package]]
name = "rprompt"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b386f4748bdae2aefc96857f5fda07647f851d089420e577831e2a14b45230f8"
[[package]] [[package]]
name = "rustc-demangle" name = "rustc-demangle"
version = "0.1.16" version = "0.1.16"

View File

@ -19,3 +19,5 @@ regex = "1.3.7"
lazy_static = "1.4.0" lazy_static = "1.4.0"
parking_lot = "0.10.2" parking_lot = "0.10.2"
structopt = "0.3.13" structopt = "0.3.13"
rpassword = "4.0.5"
rprompt = "1.0.5"

View File

@ -26,6 +26,7 @@ const ILIAS_URL: &'static str = "https://ilias.studium.kit.edu/";
struct ILIAS { struct ILIAS {
opt: Opt, opt: Opt,
// TODO: use these for re-authentication in case of session timeout/invalidation
user: String, user: String,
pass: String, pass: String,
path_prefix: PathBuf, path_prefix: PathBuf,
@ -226,7 +227,7 @@ impl ILIAS {
login_soup = BeautifulSoup(otp_response.text, 'lxml') login_soup = BeautifulSoup(otp_response.text, 'lxml')
*/ */
let saml = Selector::parse(r#"input[name="SAMLResponse"]"#).unwrap(); let saml = Selector::parse(r#"input[name="SAMLResponse"]"#).unwrap();
let saml = dom.select(&saml).next().expect("no SAML response"); let saml = dom.select(&saml).next().expect("no SAML response, incorrect password?");
let relay_state = Selector::parse(r#"input[name="RelayState"]"#).unwrap(); let relay_state = Selector::parse(r#"input[name="RelayState"]"#).unwrap();
let relay_state = dom.select(&relay_state).next().expect("no relay state"); let relay_state = dom.select(&relay_state).next().expect("no relay state");
println!("Logging into ILIAS.."); println!("Logging into ILIAS..");
@ -287,7 +288,9 @@ async fn main() {
*TASKS_RUNNING.lock() -= 1; *TASKS_RUNNING.lock() -= 1;
PANIC_HOOK.lock()(info); PANIC_HOOK.lock()(info);
})); }));
let mut ilias = match ILIAS::login::<&str, &str>(opt, env!("ILIAS_USER"), env!("ILIAS_PASS")).await { let user = rprompt::prompt_reply_stdout("Username: ").unwrap();
let pass = rpassword::read_password_from_tty(Some("Password: ")).unwrap();
let mut ilias = match ILIAS::login::<_, String>(opt, user, pass).await {
Ok(ilias) => ilias, Ok(ilias) => ilias,
Err(e) => panic!("error: {:?}", e) Err(e) => panic!("error: {:?}", e)
}; };