Skip to content

Commit

Permalink
Handle invalid passwords
Browse files Browse the repository at this point in the history
  • Loading branch information
bubelov committed Oct 15, 2024
1 parent 62a1d8b commit 74b32b5
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/command/setup.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{settings, verbosity, Result};
use crate::{rpc, settings, verbosity, Result};
use clap::Args;
use colored_json::ToColoredJson;
use serde_json::json;
Expand Down Expand Up @@ -28,8 +28,22 @@ pub struct LoginArgs {
}

pub fn login(args: &LoginArgs) -> Result<()> {
let old_password = settings::get_str("password")?;
settings::put_str("password", &args.password)?;
Ok(())
match rpc::call("get_area", json!({ "id": "th" })) {
Ok(res) => match res.error {
Some(_) => {
res.print()?;
settings::put_str("password", &old_password)?;
Err("Password is likely wrong")?
}
None => Ok(()),
},
Err(e) => {
settings::put_str("password", &old_password)?;
Err(e)?
}
}
}

#[derive(Args)]
Expand Down

0 comments on commit 74b32b5

Please sign in to comment.