2 files changed
+35
-33
src/account/login/process.rs
+33
-2
@@ -5,6 +5,7 @@ use std::{
5
6
use anyhow::{anyhow, Result};
7
use console::style;
8
+use dialoguer::{theme::ColorfulTheme, Input, Password};
9
use reqwest::Client;
10
use serde::{Deserialize, Serialize};
11
use spinners::Spinner;
@@ -32,7 +33,37 @@ struct LoginResult {
33
data: Data,
34
}
35
35
-pub async fn process_login(args: LoginArgs) -> Result<()> {
36
+pub async fn process_login() -> Result<CommandResult> {
37
+ println!("Provide your login credentials.");
38
+ let username = Input::<String>::with_theme(&ColorfulTheme::default())
39
+ .with_prompt("Username")
40
+ .interact()
41
+ .unwrap();
42
+ let password = Password::with_theme(&ColorfulTheme::default())
43
+ .with_prompt("Password")
44
+ .interact()
45
+ .unwrap();
46
+
47
+ let spinner = Spinner::new(
48
+ spinners::Spinners::SimpleDotsScrolling,
49
+ style("Logging in...").green().bold().to_string(),
50
+ );
51
+
52
+ match do_process_login(LoginArgs { username, password }).await {
53
+ Ok(_) => Ok(CommandResult {
54
+ spinner,
55
+ symbol: "✅".to_owned(),
56
+ msg: "You are logged in!".to_owned(),
57
+ }),
58
+ Err(e) => Ok(CommandResult {
59
+ spinner,
60
+ symbol: "😩".to_owned(),
61
+ msg: format!("Failed to login: {e}"),
62
+ }),
63
+ }
64
+}
65
+
66
+async fn do_process_login(args: LoginArgs) -> Result<()> {
67
let login_params = LoginParams {
68
user: User {
69
email: args.username,
@@ -86,7 +117,7 @@ pub async fn process_login(args: LoginArgs) -> Result<()> {
117
pub async fn process_logout() -> Result<CommandResult> {
118
let spinner = Spinner::new(
119
spinners::Spinners::SimpleDotsScrolling,
89
- style("⏳ Logging you out...").green().bold().to_string(),
120
+ style("Logging you out...").green().bold().to_string(),
121
);
122
match home::home_dir() {
123
Some(path) => {
src/main.rs
+2
-31
@@ -1,7 +1,7 @@
1
use anyhow::{anyhow, Result};
2
use clap::Parser;
3
use console::{style, Term};
4
-use dialoguer::{theme::ColorfulTheme, Input, Password, Select};
4
+use dialoguer::{theme::ColorfulTheme, Select};
5
use dotenv::dotenv;
6
use std::{fs::OpenOptions, path::PathBuf, str::FromStr};
7
@@ -15,7 +15,6 @@ use smbpndk_cli::{
15
projects,
16
util::CommandResult,
17
};
18
-use spinners::Spinner;
18
19
use tracing::subscriber::set_global_default;
20
use tracing_bunyan_formatter::{BunyanFormattingLayer, JsonStorageLayer};
@@ -88,35 +87,7 @@ async fn run() -> Result<CommandResult> {
87
}
88
89
match cli.command {
91
- Commands::Login {} => {
92
- println!("Provide your login credentials.");
93
- let username = Input::<String>::with_theme(&ColorfulTheme::default())
94
- .with_prompt("Username")
95
- .interact()
96
- .unwrap();
97
- let password = Password::with_theme(&ColorfulTheme::default())
98
- .with_prompt("Password")
99
- .interact()
100
- .unwrap();
101
-
102
- let spinner = Spinner::new(
103
- spinners::Spinners::SimpleDotsScrolling,
104
- style("⏳ Logging in...").green().bold().to_string(),
105
- );
106
-
107
- match process_login(LoginArgs { username, password }).await {
108
- Ok(_) => Ok(CommandResult {
109
- spinner,
110
- symbol: "✅".to_owned(),
111
- msg: "You are logged in!".to_owned(),
112
- }),
113
- Err(e) => Ok(CommandResult {
114
- spinner,
115
- symbol: "😩".to_owned(),
116
- msg: format!("Failed to login: {e}"),
117
- }),
118
- }
119
- }
90
+ Commands::Login {} => process_login().await,
91
Commands::Logout {} => process_logout().await,
92
Commands::Signup {} => {
93
let signup_methods = vec![SignupMethod::Email, SignupMethod::GitHub];