Merge pull request #81 from dyc3/remove-authenticator
add account removal, closes #10
This commit is contained in:
commit
47be84aaca
3 changed files with 77 additions and 0 deletions
|
@ -66,6 +66,16 @@ impl Manifest {
|
|||
self.accounts.push(Arc::new(Mutex::new(account)));
|
||||
}
|
||||
|
||||
pub fn remove_account(&mut self, account_name: String) {
|
||||
let index = self
|
||||
.accounts
|
||||
.iter()
|
||||
.position(|a| a.lock().unwrap().account_name == account_name)
|
||||
.unwrap();
|
||||
self.accounts.remove(index);
|
||||
self.entries.remove(index);
|
||||
}
|
||||
|
||||
pub fn save(&self) -> anyhow::Result<()> {
|
||||
ensure!(
|
||||
self.entries.len() == self.accounts.len(),
|
||||
|
|
53
src/main.rs
53
src/main.rs
|
@ -85,6 +85,10 @@ fn main() {
|
|||
App::new("setup")
|
||||
.about("Set up a new account with steamguard-cli")
|
||||
)
|
||||
.subcommand(
|
||||
App::new("remove")
|
||||
.about("Remove the authenticator from an account.")
|
||||
)
|
||||
.subcommand(
|
||||
App::new("debug")
|
||||
.arg(
|
||||
|
@ -298,6 +302,55 @@ fn main() {
|
|||
}
|
||||
|
||||
manifest.save();
|
||||
} else if let Some(_) = matches.subcommand_matches("remove") {
|
||||
println!(
|
||||
"This will remove the mobile authenticator from {} accounts: {}",
|
||||
selected_accounts.len(),
|
||||
selected_accounts
|
||||
.iter()
|
||||
.map(|a| a.lock().unwrap().account_name.clone())
|
||||
.collect::<Vec<String>>()
|
||||
.join(", ")
|
||||
);
|
||||
|
||||
print!("Do you want to continue? [yN] ");
|
||||
match prompt().as_str() {
|
||||
"y" => {}
|
||||
_ => {
|
||||
println!("Aborting!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
let mut successful = vec![];
|
||||
for a in selected_accounts {
|
||||
let account = a.lock().unwrap();
|
||||
match account.remove_authenticator(None) {
|
||||
Ok(success) => {
|
||||
if success {
|
||||
println!("Removed authenticator from {}", account.account_name);
|
||||
successful.push(account.account_name.clone());
|
||||
} else {
|
||||
println!(
|
||||
"Failed to remove authenticator from {}",
|
||||
account.account_name
|
||||
);
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
println!(
|
||||
"Unexpected error when removing authenticator from {}: {}",
|
||||
account.account_name, err
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for account_name in successful {
|
||||
manifest.remove_account(account_name);
|
||||
}
|
||||
|
||||
manifest.save().expect("Failed to save manifest.");
|
||||
} else {
|
||||
let server_time = steamapi::get_server_time();
|
||||
for account in selected_accounts {
|
||||
|
|
|
@ -11,6 +11,7 @@ use reqwest::{
|
|||
use scraper::{Html, Selector};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::{collections::HashMap, convert::TryInto};
|
||||
use steamapi::SteamApiClient;
|
||||
pub use userlogin::{LoginError, UserLogin};
|
||||
#[macro_use]
|
||||
extern crate lazy_static;
|
||||
|
@ -245,6 +246,19 @@ impl SteamGuardAccount {
|
|||
ensure!(resp.success);
|
||||
Ok(resp.html)
|
||||
}
|
||||
|
||||
/// Removes the mobile authenticator from the steam account. If this operation succeeds, this object can no longer be considered valid.
|
||||
/// Returns whether or not the operation was successful.
|
||||
pub fn remove_authenticator(&self, revocation_code: Option<String>) -> anyhow::Result<bool> {
|
||||
ensure!(
|
||||
matches!(revocation_code, Some(_)) || !self.revocation_code.is_empty(),
|
||||
"Revocation code not provided."
|
||||
);
|
||||
let client: SteamApiClient = SteamApiClient::new(self.session.clone());
|
||||
let resp =
|
||||
client.remove_authenticator(revocation_code.unwrap_or(self.revocation_code.clone()))?;
|
||||
Ok(resp.success)
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_confirmations(text: String) -> anyhow::Result<Vec<Confirmation>> {
|
||||
|
|
Loading…
Reference in a new issue