Skip to content

Commit

Permalink
refactor(password-reset): add proper error handling and improve some …
Browse files Browse the repository at this point in the history
…wording
  • Loading branch information
nicotsx committed Feb 11, 2024
1 parent cff7400 commit 53ac420
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub enum RuntipiMainCommand {
Update(UpdateCommand),
/// Manage your apps
App(AppCommand),
/// Reset your runtipi password
/// Initiate a password reset for the admin user
ResetPassword,
/// Debug your runtipi instance
Debug,
Expand Down
27 changes: 21 additions & 6 deletions src/commands/reset_password.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
use std::{fs::File, path::PathBuf};
use std::env;
use colored::Colorize;
use std::env;
use std::{fs::File, path::PathBuf};

pub fn run() {
let root_folder: PathBuf = env::current_dir().expect("Unable to get current directory");
let mut _reset_password_request = File::create(root_folder.join("state").join("password-change-request"));
print!("{}", "✓ ".green());
println!("Password reset request created. Head back to the dashboard to set a new password.")
}
let reset_password_request = File::create(root_folder.join("state").join("password-change-request"));

match reset_password_request {
Ok(_) => {
println!(
"{} Password reset request created. Head back to the dashboard to set a new password.",
"✓".green()
)
}
Err(_) => {
println!(
"{} Unable to create password reset request. You can manually create an empty file at {} to initiate a password reset.",
"✗".red(),
root_folder.join("state").join("password-change-request").to_str().unwrap()
);
return;
}
}
}
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::commands::update::UpdateArgs;
fn main() {
let args = RuntipiArgs::parse();

println!("{}", "Welcome to Runtipi CLI ✨".green());
println!("{}", "Welcome to Runtipi CLI ✨\n".green());

match args.command {
args::RuntipiMainCommand::Start(args) => {
Expand Down

0 comments on commit 53ac420

Please sign in to comment.