From 11f2d8a1f44c08bf746fe9517b6adeda0d5070d6 Mon Sep 17 00:00:00 2001 From: dushixiang Date: Wed, 14 Apr 2021 22:27:12 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=87=8D=E7=BD=AEtotp?= =?UTF-8?q?=E7=9A=84=E5=91=BD=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/faq.md | 31 ++++++++++++++++++++++++++++++- main.go | 5 ++++- pkg/config/config.go | 2 ++ server/api/routes.go | 20 ++++++++++++++++++-- 4 files changed, 54 insertions(+), 4 deletions(-) diff --git a/docs/faq.md b/docs/faq.md index 10ca15d..9402d86 100644 --- a/docs/faq.md +++ b/docs/faq.md @@ -18,7 +18,8 @@ location / {
访问realvnc提示验证失败? -把加密类型修改为 Prefer On +1. 把密码类型修改为VNC +2. 把加密类型修改为 Prefer On
@@ -88,3 +89,31 @@ Mar 5 20:00:16.923 [DEBU] 用户「admin」密码初始化为: next-terminal +
+ TOTP客户端丢了怎么办? +首先需要进入程序所在目录,使用docker安装的程序目录为:/usr/local/next-terminal + +执行命令 + +```shell +./next-terminal --reset-totp admin +``` + +其中 admin 为用户登录账号,成功之后会输出 + +``` shell + + _______ __ ___________ .__ .__ + \ \ ____ ___ ____/ |_ \__ ___/__________ _____ |__| ____ _____ | | + / | \_/ __ \\ \/ /\ __\ | |_/ __ \_ __ \/ \| |/ \\__ \ | | +/ | \ ___/ > < | | | |\ ___/| | \/ Y Y \ | | \/ __ \| |__ +\____|__ /\___ >__/\_ \ |__| |____| \___ >__| |__|_| /__|___| (____ /____/ + \/ \/ \/ \/ \/ \/ \/ v0.3.0 + +当前数据库模式为:mysql +Mar 5 20:00:16.923 [DEBU] 用户「admin」已重置TOTP + +``` + +
+ diff --git a/main.go b/main.go index 597d7d6..5a9b938 100644 --- a/main.go +++ b/main.go @@ -39,7 +39,10 @@ func Run() error { e := api.SetupRoutes(db) if global.Config.ResetPassword != "" { - return api.ResetPassword() + return api.ResetPassword(global.Config.ResetPassword) + } + if global.Config.ResetTotp != "" { + return api.ResetTotp(global.Config.ResetTotp) } sessionRepo := repository.NewSessionRepository(db) propertyRepo := repository.NewPropertyRepository(db) diff --git a/pkg/config/config.go b/pkg/config/config.go index 5fe0868..03e79e5 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -18,6 +18,7 @@ type Config struct { Mysql *Mysql Sqlite *Sqlite ResetPassword string + ResetTotp string } type Mysql struct { @@ -83,6 +84,7 @@ func SetupConfig() *Config { Key: viper.GetString("server.key"), }, ResetPassword: viper.GetString("reset-password"), + ResetTotp: viper.GetString("reset-totp"), Debug: viper.GetBool("debug"), Demo: viper.GetBool("demo"), } diff --git a/server/api/routes.go b/server/api/routes.go index 0a67e1b..ad545da 100644 --- a/server/api/routes.go +++ b/server/api/routes.go @@ -275,8 +275,8 @@ func InitDBData() (err error) { return nil } -func ResetPassword() error { - user, err := userRepository.FindByUsername(global.Config.ResetPassword) +func ResetPassword(username string) error { + user, err := userRepository.FindByUsername(username) if err != nil { return err } @@ -296,6 +296,22 @@ func ResetPassword() error { return nil } +func ResetTotp(username string) error { + user, err := userRepository.FindByUsername(username) + if err != nil { + return err + } + u := &model.User{ + TOTPSecret: "-", + ID: user.ID, + } + if err := userRepository.Update(u); err != nil { + return err + } + log.Debugf("用户「%v」已重置TOTP", user.Username) + return nil +} + func SetupCache() *cache.Cache { // 配置缓存器 mCache := cache.New(5*time.Minute, 10*time.Minute)