4 files changed
+60
src/account/forgot/mod.rs
new
+53
@@ -0,0 +1,53 @@
1
+use anyhow::Result;
2
+use console::style;
3
+use dialoguer::{theme::ColorfulTheme, Input};
4
+use reqwest::{Client, StatusCode};
5
+use serde::Serialize;
6
+use spinners::Spinner;
7
+
8
+use crate::{constants::BASE_URL, util::CommandResult};
9
+
10
+#[derive(Debug, Serialize)]
11
+struct Args {
12
+ user: Email,
13
+}
14
+
15
+#[derive(Debug, Serialize)]
16
+struct Email {
17
+ email: String,
18
+}
19
+
20
+pub async fn process() -> Result<CommandResult> {
21
+ println!("Provide your login credentials.");
22
+ let email = Input::<String>::with_theme(&ColorfulTheme::default())
23
+ .with_prompt("Email")
24
+ .interact()
25
+ .unwrap();
26
+ let spinner = Spinner::new(
27
+ spinners::Spinners::SimpleDotsScrolling,
28
+ style("⏳ Logging in...").green().bold().to_string(),
29
+ );
30
+
31
+ let params = Args {
32
+ user: Email { email },
33
+ };
34
+
35
+ let response = Client::new()
36
+ .post([BASE_URL, "/v1/users/password"].join(""))
37
+ .json(¶ms)
38
+ .send()
39
+ .await?;
40
+
41
+ match response.status() {
42
+ StatusCode::OK => Ok(CommandResult {
43
+ spinner,
44
+ symbol: "✅".to_owned(),
45
+ msg: "Check your email and follow the instruction to reset your password.".to_owned(),
46
+ }),
47
+ _ => Ok(CommandResult {
48
+ spinner,
49
+ symbol: "✅".to_owned(),
50
+ msg: "You are logged in!".to_owned(),
51
+ }),
52
+ }
53
+}
src/account/mod.rs
+1
@@ -1,3 +1,4 @@
1
+pub mod forgot;
2
pub mod login;
3
pub mod model;
4
pub mod signup;
src/cli/mod.rs
+4
@@ -22,6 +22,10 @@ pub enum Commands {
22
about = "Login to your account. To create an account, use smb signup or visit https://smbpndk.com"
23
)]
24
Login {},
25
+
26
+ #[clap(about = "Forgot email? Use this command to reset your password.")]
27
+ Forgot {},
28
+
29
#[clap(about = "Manage your projects. Add, delete, edit. Need authentication.")]
30
Projects {
31
#[clap(subcommand)]
src/main.rs
+2
@@ -7,6 +7,7 @@ use std::{fs::OpenOptions, path::PathBuf, str::FromStr};
7
8
use smbpndk_cli::{
9
account::{
10
+ self,
11
login::{process_login, LoginArgs},
12
signup::{signup_with_email, signup_with_github, SignupMethod},
13
},
@@ -130,6 +131,7 @@ async fn run() -> Result<CommandResult> {
131
SignupMethod::GitHub => signup_with_github().await,
132
}
133
}
134
+ Commands::Forgot {} => account::forgot::process().await,
135
Commands::Projects { command } => projects::process(command).await,
136
}
137
}