actually handle account link errors
This commit is contained in:
parent
298d29dc07
commit
467e669fb8
2 changed files with 36 additions and 15 deletions
28
src/main.rs
28
src/main.rs
|
@ -9,8 +9,8 @@ use std::{
|
|||
sync::{Arc, Mutex},
|
||||
};
|
||||
use steamguard::{
|
||||
steamapi, AccountLinker, Confirmation, ConfirmationType, FinalizeLinkError, LoginError,
|
||||
SteamGuardAccount, UserLogin,
|
||||
steamapi, AccountLinkError, AccountLinker, Confirmation, ConfirmationType, FinalizeLinkError,
|
||||
LoginError, SteamGuardAccount, UserLogin,
|
||||
};
|
||||
use termion::{
|
||||
event::{Event, Key},
|
||||
|
@ -136,6 +136,22 @@ fn main() {
|
|||
account = a;
|
||||
break;
|
||||
}
|
||||
Err(AccountLinkError::MustRemovePhoneNumber) => {
|
||||
println!("There is already a phone number on this account, please remove it and try again.");
|
||||
return;
|
||||
}
|
||||
Err(AccountLinkError::MustProvidePhoneNumber) => {
|
||||
print!("Enter your phone number:");
|
||||
linker.phone_number = prompt();
|
||||
}
|
||||
Err(AccountLinkError::AuthenticatorPresent) => {
|
||||
println!("An authenticator is already present on this account.");
|
||||
return;
|
||||
}
|
||||
Err(AccountLinkError::MustConfirmEmail) => {
|
||||
println!("Check your email and click the link.");
|
||||
pause();
|
||||
}
|
||||
Err(err) => {
|
||||
error!(
|
||||
"Failed to link authenticator. Account has not been linked. {}",
|
||||
|
@ -510,7 +526,6 @@ fn do_login_raw() -> anyhow::Result<steamapi::Session> {
|
|||
}
|
||||
Err(LoginError::Need2FA) => {
|
||||
print!("Enter 2fa code: ");
|
||||
let server_time = steamapi::get_server_time();
|
||||
login.twofactor_code = prompt();
|
||||
}
|
||||
Err(LoginError::NeedCaptcha { captcha_gid }) => {
|
||||
|
@ -535,6 +550,13 @@ fn do_login_raw() -> anyhow::Result<steamapi::Session> {
|
|||
}
|
||||
}
|
||||
|
||||
fn pause() {
|
||||
println!("Press any key to continue...");
|
||||
let mut stdout = stdout().into_raw_mode().unwrap();
|
||||
stdout.flush().unwrap();
|
||||
stdin().events().next();
|
||||
}
|
||||
|
||||
fn demo_confirmation_menu() {
|
||||
info!("showing demo menu");
|
||||
let (accept, deny) = prompt_confirmation_menu(vec![
|
||||
|
|
|
@ -1,15 +1,16 @@
|
|||
use crate::{
|
||||
steamapi::{AddAuthenticatorResponse, Session, SteamApiClient, FinalizeAddAuthenticatorResponse},
|
||||
steamapi::{
|
||||
AddAuthenticatorResponse, FinalizeAddAuthenticatorResponse, Session, SteamApiClient,
|
||||
},
|
||||
SteamGuardAccount,
|
||||
};
|
||||
use log::*;
|
||||
use thiserror::Error;
|
||||
use std::fmt::Display;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct AccountLinker {
|
||||
device_id: String,
|
||||
phone_number: String,
|
||||
pub phone_number: String,
|
||||
pub account: Option<SteamGuardAccount>,
|
||||
pub finalized: bool,
|
||||
sent_confirmation_email: bool,
|
||||
|
@ -31,7 +32,6 @@ impl AccountLinker {
|
|||
}
|
||||
|
||||
pub fn link(&mut self) -> anyhow::Result<SteamGuardAccount, AccountLinkError> {
|
||||
|
||||
let has_phone = self.client.has_phone()?;
|
||||
|
||||
if has_phone && !self.phone_number.is_empty() {
|
||||
|
@ -81,9 +81,9 @@ impl AccountLinker {
|
|||
) -> anyhow::Result<(), FinalizeLinkError> {
|
||||
let time = crate::steamapi::get_server_time();
|
||||
let code = account.generate_code(time);
|
||||
let resp: FinalizeAddAuthenticatorResponse = self
|
||||
.client
|
||||
.finalize_authenticator(sms_code.clone(), code, time)?;
|
||||
let resp: FinalizeAddAuthenticatorResponse =
|
||||
self.client
|
||||
.finalize_authenticator(sms_code.clone(), code, time)?;
|
||||
info!("finalize response status: {}", resp.status);
|
||||
|
||||
match resp.status {
|
||||
|
@ -94,7 +94,9 @@ impl AccountLinker {
|
|||
}
|
||||
|
||||
if !resp.success {
|
||||
return Err(FinalizeLinkError::Failure { status: resp.status })?;
|
||||
return Err(FinalizeLinkError::Failure {
|
||||
status: resp.status,
|
||||
})?;
|
||||
}
|
||||
|
||||
if resp.want_more {
|
||||
|
@ -122,9 +124,6 @@ pub enum AccountLinkError {
|
|||
/// User need to click link from confirmation email
|
||||
#[error("An email has been sent to the user's email, click the link in that email.")]
|
||||
MustConfirmEmail,
|
||||
/// Must provide an SMS code
|
||||
#[error("Awaiting finalization")]
|
||||
AwaitingFinalization,
|
||||
#[error("Authenticator is already present.")]
|
||||
AuthenticatorPresent,
|
||||
#[error(transparent)]
|
||||
|
@ -139,7 +138,7 @@ pub enum FinalizeLinkError {
|
|||
#[error("Steam wants more 2fa codes for verification.")]
|
||||
WantMore,
|
||||
#[error("Finalization was not successful. Status code {status:?}")]
|
||||
Failure{ status: i32 },
|
||||
Failure { status: i32 },
|
||||
#[error(transparent)]
|
||||
Unknown(#[from] anyhow::Error),
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue