commit
17a4ebe813
3 changed files with 39 additions and 7 deletions
|
@ -116,6 +116,15 @@ impl Manifest {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn account_exists(&self, account_name: &String) -> bool {
|
||||||
|
for entry in &self.entries {
|
||||||
|
if &entry.account_name == account_name {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
pub fn add_account(&mut self, account: SteamGuardAccount) {
|
pub fn add_account(&mut self, account: SteamGuardAccount) {
|
||||||
debug!("adding account to manifest: {}", account.account_name);
|
debug!("adding account to manifest: {}", account.account_name);
|
||||||
let steamid = account.session.as_ref().map_or(0, |s| s.steam_id);
|
let steamid = account.session.as_ref().map_or(0, |s| s.steam_id);
|
||||||
|
@ -136,6 +145,10 @@ impl Manifest {
|
||||||
let file = File::open(path)?;
|
let file = File::open(path)?;
|
||||||
let reader = BufReader::new(file);
|
let reader = BufReader::new(file);
|
||||||
let account: SteamGuardAccount = serde_json::from_reader(reader)?;
|
let account: SteamGuardAccount = serde_json::from_reader(reader)?;
|
||||||
|
ensure!(
|
||||||
|
!self.account_exists(&account.account_name),
|
||||||
|
"Account already exists in manifest, please remove it first."
|
||||||
|
);
|
||||||
self.add_account(account);
|
self.add_account(account);
|
||||||
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
|
|
31
src/main.rs
31
src/main.rs
|
@ -210,7 +210,16 @@ fn main() {
|
||||||
|
|
||||||
if matches.is_present("setup") {
|
if matches.is_present("setup") {
|
||||||
println!("Log in to the account that you want to link to steamguard-cli");
|
println!("Log in to the account that you want to link to steamguard-cli");
|
||||||
let session = do_login_raw().expect("Failed to log in. Account has not been linked.");
|
print!("Username: ");
|
||||||
|
let username = tui::prompt();
|
||||||
|
if manifest.account_exists(&username) {
|
||||||
|
error!(
|
||||||
|
"Account {} already exists in manifest, remove it first",
|
||||||
|
username
|
||||||
|
);
|
||||||
|
}
|
||||||
|
let session =
|
||||||
|
do_login_raw(username).expect("Failed to log in. Account has not been linked.");
|
||||||
|
|
||||||
let mut linker = AccountLinker::new(session);
|
let mut linker = AccountLinker::new(session);
|
||||||
let account: SteamGuardAccount;
|
let account: SteamGuardAccount;
|
||||||
|
@ -456,10 +465,19 @@ fn main() {
|
||||||
"Failed to remove authenticator from {}",
|
"Failed to remove authenticator from {}",
|
||||||
account.account_name
|
account.account_name
|
||||||
);
|
);
|
||||||
|
match tui::prompt_char(
|
||||||
|
"Would you like to remove it from the manifest anyway?",
|
||||||
|
"yN",
|
||||||
|
) {
|
||||||
|
'y' => {
|
||||||
|
successful.push(account.account_name.clone());
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
println!(
|
error!(
|
||||||
"Unexpected error when removing authenticator from {}: {}",
|
"Unexpected error when removing authenticator from {}: {}",
|
||||||
account.account_name, err
|
account.account_name, err
|
||||||
);
|
);
|
||||||
|
@ -476,7 +494,10 @@ fn main() {
|
||||||
let server_time = steamapi::get_server_time();
|
let server_time = steamapi::get_server_time();
|
||||||
debug!("Time used to generate codes: {}", server_time);
|
debug!("Time used to generate codes: {}", server_time);
|
||||||
for account in selected_accounts {
|
for account in selected_accounts {
|
||||||
info!("Generating code for {}", account.lock().unwrap().account_name);
|
info!(
|
||||||
|
"Generating code for {}",
|
||||||
|
account.lock().unwrap().account_name
|
||||||
|
);
|
||||||
trace!("{:?}", account);
|
trace!("{:?}", account);
|
||||||
let code = account.lock().unwrap().generate_code(server_time);
|
let code = account.lock().unwrap().generate_code(server_time);
|
||||||
println!("{}", code);
|
println!("{}", code);
|
||||||
|
@ -506,9 +527,7 @@ fn do_login(account: &mut SteamGuardAccount) -> anyhow::Result<()> {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn do_login_raw() -> anyhow::Result<steamapi::Session> {
|
fn do_login_raw(username: String) -> anyhow::Result<steamapi::Session> {
|
||||||
print!("Username: ");
|
|
||||||
let username = tui::prompt();
|
|
||||||
let _ = std::io::stdout().flush();
|
let _ = std::io::stdout().flush();
|
||||||
let password = rpassword::prompt_password_stdout("Password: ").unwrap();
|
let password = rpassword::prompt_password_stdout("Password: ").unwrap();
|
||||||
if password.len() > 0 {
|
if password.len() > 0 {
|
||||||
|
|
|
@ -96,7 +96,7 @@ fn prompt_char_impl(input: &mut impl Read, text: &str, chars: &str) -> char {
|
||||||
}
|
}
|
||||||
|
|
||||||
let answer_char = answer.chars().collect::<Vec<char>>()[0];
|
let answer_char = answer.chars().collect::<Vec<char>>()[0];
|
||||||
if chars.contains(answer_char) {
|
if chars.to_ascii_lowercase().contains(answer_char) {
|
||||||
return answer_char;
|
return answer_char;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue