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},
|
sync::{Arc, Mutex},
|
||||||
};
|
};
|
||||||
use steamguard::{
|
use steamguard::{
|
||||||
steamapi, AccountLinker, Confirmation, ConfirmationType, FinalizeLinkError, LoginError,
|
steamapi, AccountLinkError, AccountLinker, Confirmation, ConfirmationType, FinalizeLinkError,
|
||||||
SteamGuardAccount, UserLogin,
|
LoginError, SteamGuardAccount, UserLogin,
|
||||||
};
|
};
|
||||||
use termion::{
|
use termion::{
|
||||||
event::{Event, Key},
|
event::{Event, Key},
|
||||||
|
@ -136,6 +136,22 @@ fn main() {
|
||||||
account = a;
|
account = a;
|
||||||
break;
|
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) => {
|
Err(err) => {
|
||||||
error!(
|
error!(
|
||||||
"Failed to link authenticator. Account has not been linked. {}",
|
"Failed to link authenticator. Account has not been linked. {}",
|
||||||
|
@ -510,7 +526,6 @@ fn do_login_raw() -> anyhow::Result<steamapi::Session> {
|
||||||
}
|
}
|
||||||
Err(LoginError::Need2FA) => {
|
Err(LoginError::Need2FA) => {
|
||||||
print!("Enter 2fa code: ");
|
print!("Enter 2fa code: ");
|
||||||
let server_time = steamapi::get_server_time();
|
|
||||||
login.twofactor_code = prompt();
|
login.twofactor_code = prompt();
|
||||||
}
|
}
|
||||||
Err(LoginError::NeedCaptcha { captcha_gid }) => {
|
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() {
|
fn demo_confirmation_menu() {
|
||||||
info!("showing demo menu");
|
info!("showing demo menu");
|
||||||
let (accept, deny) = prompt_confirmation_menu(vec![
|
let (accept, deny) = prompt_confirmation_menu(vec![
|
||||||
|
|
|
@ -1,15 +1,16 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
steamapi::{AddAuthenticatorResponse, Session, SteamApiClient, FinalizeAddAuthenticatorResponse},
|
steamapi::{
|
||||||
|
AddAuthenticatorResponse, FinalizeAddAuthenticatorResponse, Session, SteamApiClient,
|
||||||
|
},
|
||||||
SteamGuardAccount,
|
SteamGuardAccount,
|
||||||
};
|
};
|
||||||
use log::*;
|
use log::*;
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
use std::fmt::Display;
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct AccountLinker {
|
pub struct AccountLinker {
|
||||||
device_id: String,
|
device_id: String,
|
||||||
phone_number: String,
|
pub phone_number: String,
|
||||||
pub account: Option<SteamGuardAccount>,
|
pub account: Option<SteamGuardAccount>,
|
||||||
pub finalized: bool,
|
pub finalized: bool,
|
||||||
sent_confirmation_email: bool,
|
sent_confirmation_email: bool,
|
||||||
|
@ -31,7 +32,6 @@ impl AccountLinker {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn link(&mut self) -> anyhow::Result<SteamGuardAccount, AccountLinkError> {
|
pub fn link(&mut self) -> anyhow::Result<SteamGuardAccount, AccountLinkError> {
|
||||||
|
|
||||||
let has_phone = self.client.has_phone()?;
|
let has_phone = self.client.has_phone()?;
|
||||||
|
|
||||||
if has_phone && !self.phone_number.is_empty() {
|
if has_phone && !self.phone_number.is_empty() {
|
||||||
|
@ -81,9 +81,9 @@ impl AccountLinker {
|
||||||
) -> anyhow::Result<(), FinalizeLinkError> {
|
) -> anyhow::Result<(), FinalizeLinkError> {
|
||||||
let time = crate::steamapi::get_server_time();
|
let time = crate::steamapi::get_server_time();
|
||||||
let code = account.generate_code(time);
|
let code = account.generate_code(time);
|
||||||
let resp: FinalizeAddAuthenticatorResponse = self
|
let resp: FinalizeAddAuthenticatorResponse =
|
||||||
.client
|
self.client
|
||||||
.finalize_authenticator(sms_code.clone(), code, time)?;
|
.finalize_authenticator(sms_code.clone(), code, time)?;
|
||||||
info!("finalize response status: {}", resp.status);
|
info!("finalize response status: {}", resp.status);
|
||||||
|
|
||||||
match resp.status {
|
match resp.status {
|
||||||
|
@ -94,7 +94,9 @@ impl AccountLinker {
|
||||||
}
|
}
|
||||||
|
|
||||||
if !resp.success {
|
if !resp.success {
|
||||||
return Err(FinalizeLinkError::Failure { status: resp.status })?;
|
return Err(FinalizeLinkError::Failure {
|
||||||
|
status: resp.status,
|
||||||
|
})?;
|
||||||
}
|
}
|
||||||
|
|
||||||
if resp.want_more {
|
if resp.want_more {
|
||||||
|
@ -122,9 +124,6 @@ pub enum AccountLinkError {
|
||||||
/// User need to click link from confirmation email
|
/// 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.")]
|
#[error("An email has been sent to the user's email, click the link in that email.")]
|
||||||
MustConfirmEmail,
|
MustConfirmEmail,
|
||||||
/// Must provide an SMS code
|
|
||||||
#[error("Awaiting finalization")]
|
|
||||||
AwaitingFinalization,
|
|
||||||
#[error("Authenticator is already present.")]
|
#[error("Authenticator is already present.")]
|
||||||
AuthenticatorPresent,
|
AuthenticatorPresent,
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
|
@ -139,7 +138,7 @@ pub enum FinalizeLinkError {
|
||||||
#[error("Steam wants more 2fa codes for verification.")]
|
#[error("Steam wants more 2fa codes for verification.")]
|
||||||
WantMore,
|
WantMore,
|
||||||
#[error("Finalization was not successful. Status code {status:?}")]
|
#[error("Finalization was not successful. Status code {status:?}")]
|
||||||
Failure{ status: i32 },
|
Failure { status: i32 },
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
Unknown(#[from] anyhow::Error),
|
Unknown(#[from] anyhow::Error),
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue