don't allow setup or import for account_names already in the manifest, fixes #109
This commit is contained in:
parent
a92cd5b1aa
commit
e4cf29e852
2 changed files with 17 additions and 4 deletions
|
@ -116,6 +116,15 @@ impl Manifest {
|
|||
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) {
|
||||
debug!("adding account to manifest: {}", account.account_name);
|
||||
let steamid = account.session.as_ref().map_or(0, |s| s.steam_id);
|
||||
|
@ -136,6 +145,7 @@ impl Manifest {
|
|||
let file = File::open(path)?;
|
||||
let reader = BufReader::new(file);
|
||||
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);
|
||||
|
||||
return Ok(());
|
||||
|
|
11
src/main.rs
11
src/main.rs
|
@ -210,7 +210,12 @@ fn main() {
|
|||
|
||||
if matches.is_present("setup") {
|
||||
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 account: SteamGuardAccount;
|
||||
|
@ -515,9 +520,7 @@ fn do_login(account: &mut SteamGuardAccount) -> anyhow::Result<()> {
|
|||
return Ok(());
|
||||
}
|
||||
|
||||
fn do_login_raw() -> anyhow::Result<steamapi::Session> {
|
||||
print!("Username: ");
|
||||
let username = tui::prompt();
|
||||
fn do_login_raw(username: String) -> anyhow::Result<steamapi::Session> {
|
||||
let _ = std::io::stdout().flush();
|
||||
let password = rpassword::prompt_password_stdout("Password: ").unwrap();
|
||||
if password.len() > 0 {
|
||||
|
|
Loading…
Reference in a new issue