3 files changed
+31
-2
src/account/login/process.rs
+27
-1
@@ -1,16 +1,19 @@
1
use std::{
2
- fs::{create_dir_all, OpenOptions},
2
+ fs::{self, create_dir_all, OpenOptions},
3
io::Write,
4
};
5
6
use anyhow::{anyhow, Result};
7
+use console::style;
8
use reqwest::Client;
9
use serde::{Deserialize, Serialize};
10
+use spinners::Spinner;
11
12
use crate::{
13
account::model::{Data, Status, User},
14
constants::BASE_URL,
15
debug,
16
+ util::CommandResult,
17
};
18
19
pub struct LoginArgs {
@@ -79,3 +82,26 @@ pub async fn process_login(args: LoginArgs) -> Result<()> {
82
83
Ok(())
84
}
85
+
86
+pub async fn process_logout() -> Result<CommandResult> {
87
+ let spinner = Spinner::new(
88
+ spinners::Spinners::SimpleDotsScrolling,
89
+ style("⏳ Logging you out...").green().bold().to_string(),
90
+ );
91
+ match home::home_dir() {
92
+ Some(path) => {
93
+ debug!(path.to_str().unwrap());
94
+ fs::remove_file([path.to_str().unwrap(), "/.smb/token"].join(""))?;
95
+
96
+ Ok(CommandResult {
97
+ spinner,
98
+ symbol: "✅".to_owned(),
99
+ msg: "You are logged out!".to_owned(),
100
+ })
101
+ }
102
+ None => {
103
+ let error = anyhow!("Failed to get home directory. Are you logged in?");
104
+ return Err(error);
105
+ }
106
+ }
107
+}
src/cli/mod.rs
+2
@@ -22,6 +22,8 @@ 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
+ #[clap(about = "Logout all session.")]
26
+ Logout {},
27
28
#[clap(about = "Forgot email? Use this command to reset your password.")]
29
Forgot {},
src/main.rs
+2
-1
@@ -8,7 +8,7 @@ use std::{fs::OpenOptions, path::PathBuf, str::FromStr};
8
use smbpndk_cli::{
9
account::{
10
self,
11
- login::{process_login, LoginArgs},
11
+ login::{process_login, process_logout, LoginArgs},
12
signup::{signup_with_email, signup_with_github, SignupMethod},
13
},
14
cli::{Cli, Commands},
@@ -117,6 +117,7 @@ async fn run() -> Result<CommandResult> {
117
}),
118
}
119
}
120
+ Commands::Logout {} => process_logout().await,
121
Commands::Signup {} => {
122
let signup_methods = vec![SignupMethod::Email, SignupMethod::GitHub];
123
let selection = Select::with_theme(&ColorfulTheme::default())