Skip to content

Commit

Permalink
Fix loop on bad input, and open URL in browser
Browse files Browse the repository at this point in the history
  • Loading branch information
ulyssa committed Nov 4, 2023
1 parent 1f643d9 commit 71a458c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ two other TUI clients and Element Web:
| Message editing | ✔️ | ✔️ || ✔️ |
| Room upgrades | ❌ ([#41]) | ✔️ || ✔️ |
| Localisations || 1 || 44 |
| SSO Support | ✔️ | ✔️ | ✔️ | ✔️ |
| SSO Support | ✔️ | ✔️ | ✔️ | ✔️ |
## License

Expand Down
7 changes: 3 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -642,21 +642,20 @@ async fn login(worker: Requester, settings: &ApplicationSettings) -> IambResult<
}

loop {
println!("Please select login type");
println!("[P]assword / [s]ingle sign on");
println!("Please select login type: [p]assword / [s]ingle sign on");

let mut input = String::new();
std::io::stdin().read_line(&mut input).unwrap();

let login_style = match input.chars().nth(0).map(|x| char::to_ascii_lowercase(&x)) {
let login_style = match input.chars().next().map(|c| c.to_ascii_lowercase()) {
None | Some('p') => {
let password = rpassword::prompt_password("Password: ")?;
LoginStyle::Password(password)
},
Some('s') => LoginStyle::SingleSignOn,
Some(_) => {
println!("Failed to login. Please enter 'p' or 's'");
break;
continue;
},
};

Expand Down
5 changes: 4 additions & 1 deletion src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1021,8 +1021,11 @@ impl ClientWorker {
LoginStyle::SingleSignOn => {
let resp = client
.login_sso(|url| {
let opened = format!("The following URL should have been opened in your browser:\n {url}");

async move {
println!("Open {} in a browser", url);
tokio::task::spawn_blocking(move || open::that(url));
println!("\n{opened}\n");
Ok(())
}
})
Expand Down

0 comments on commit 71a458c

Please sign in to comment.