From 92354d6847e3c919c6182ae5d479f3fb614252a9 Mon Sep 17 00:00:00 2001 From: jeessy2 <6205259+jeessy2@users.noreply.github.com> Date: Fri, 25 Oct 2024 09:42:37 +0800 Subject: [PATCH] fix: password reset issue and handle missing config file (#1290) * fix: password reset issue and handle missing config file * Add option to reset password with custom config file --- README.md | 1 + main.go | 8 ++++++-- util/messages.go | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c5d2ec0..5ab4774 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,7 @@ - 重置密码 ```bash ./ddns-go -resetPassword 123456 + ./ddns-go -resetPassword 123456 -c /Users/name/.ddns_go_config.yaml ``` - [可选] 使用 [Homebrew](https://brew.sh) 安装 [ddns-go](https://formulae.brew.sh/formula/ddns-go): diff --git a/main.go b/main.go index b3fde96..e09b6d7 100644 --- a/main.go +++ b/main.go @@ -94,8 +94,12 @@ func main() { } // 重置密码 if *newPassword != "" { - conf, _ := config.GetConfigCached() - conf.ResetPassword(*newPassword) + conf, err := config.GetConfigCached() + if err == nil { + conf.ResetPassword(*newPassword) + } else { + util.Log("配置文件 %s 不存在, 可通过-c指定配置文件", *configFilePath) + } return } // 设置跳过证书验证 diff --git a/util/messages.go b/util/messages.go index 75b310f..dfb7462 100644 --- a/util/messages.go +++ b/util/messages.go @@ -113,6 +113,7 @@ func init() { message.SetString(language.English, "登录失败次数过多,请等待 %d 分钟后再试", "Too many login failures, please try again after %d minutes") message.SetString(language.English, "用户名 %s 的密码已重置成功! 请重启ddns-go", "The password of username %s has been reset successfully! Please restart ddns-go") message.SetString(language.English, "需在 %s 之前完成用户名密码设置,请重启ddns-go", "Need to complete the username and password setting before %s, please restart ddns-go") + message.SetString(language.English, "配置文件 %s 不存在, 可通过-c指定配置文件", "Config file %s does not exist, you can specify the configuration file through -c") }