增加重置totp的命令

This commit is contained in:
dushixiang 2021-04-14 22:27:12 +08:00
parent 5cee2dd50e
commit 11f2d8a1f4
4 changed files with 54 additions and 4 deletions

View File

@ -18,7 +18,8 @@ location / {
<details> <details>
<summary>访问realvnc提示验证失败</summary> <summary>访问realvnc提示验证失败</summary>
把加密类型修改为 Prefer On 1. 把密码类型修改为VNC
2. 把加密类型修改为 Prefer On
</details> </details>
@ -88,3 +89,31 @@ Mar 5 20:00:16.923 [DEBU] 用户「admin」密码初始化为: next-terminal
</details> </details>
<details>
<summary>TOTP客户端丢了怎么办</summary>
首先需要进入程序所在目录使用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
```
</details>

View File

@ -39,7 +39,10 @@ func Run() error {
e := api.SetupRoutes(db) e := api.SetupRoutes(db)
if global.Config.ResetPassword != "" { 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) sessionRepo := repository.NewSessionRepository(db)
propertyRepo := repository.NewPropertyRepository(db) propertyRepo := repository.NewPropertyRepository(db)

View File

@ -18,6 +18,7 @@ type Config struct {
Mysql *Mysql Mysql *Mysql
Sqlite *Sqlite Sqlite *Sqlite
ResetPassword string ResetPassword string
ResetTotp string
} }
type Mysql struct { type Mysql struct {
@ -83,6 +84,7 @@ func SetupConfig() *Config {
Key: viper.GetString("server.key"), Key: viper.GetString("server.key"),
}, },
ResetPassword: viper.GetString("reset-password"), ResetPassword: viper.GetString("reset-password"),
ResetTotp: viper.GetString("reset-totp"),
Debug: viper.GetBool("debug"), Debug: viper.GetBool("debug"),
Demo: viper.GetBool("demo"), Demo: viper.GetBool("demo"),
} }

View File

@ -275,8 +275,8 @@ func InitDBData() (err error) {
return nil return nil
} }
func ResetPassword() error { func ResetPassword(username string) error {
user, err := userRepository.FindByUsername(global.Config.ResetPassword) user, err := userRepository.FindByUsername(username)
if err != nil { if err != nil {
return err return err
} }
@ -296,6 +296,22 @@ func ResetPassword() error {
return nil 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 { func SetupCache() *cache.Cache {
// 配置缓存器 // 配置缓存器
mCache := cache.New(5*time.Minute, 10*time.Minute) mCache := cache.New(5*time.Minute, 10*time.Minute)