Merge pull request #2 from mgr9525/dev

clear password
This commit is contained in:
Linsk Ruis 2020-10-11 14:37:34 +08:00 committed by GitHub
commit 48bf19dad0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

26
main.go
View File

@ -2,6 +2,7 @@ package main
import (
"flag"
"fmt"
"gokins/comm"
"gokins/core"
"gokins/mgr"
@ -13,6 +14,8 @@ import (
"github.com/gin-gonic/gin"
)
var clearPass = ""
func init() {
path, err := os.Executable()
if err != nil {
@ -29,6 +32,7 @@ func init() {
println("dir:" + dir)
flag.StringVar(&comm.Dir, "d", dir, "数据目录")
flag.StringVar(&comm.Host, "bind", ":8030", "绑定地址")
flag.StringVar(&clearPass, "clp", "", "清除用户密码(请先关闭服务在执行)")
flag.Parse()
comm.Gin = gin.Default()
}
@ -38,6 +42,9 @@ func main() {
println("InitDb err:" + err.Error())
return
}
if clearUPass() {
return
}
jwtKey := dbService.GetParam("jwt-key")
jkey := jwtKey.GetString("key")
if jkey == "" {
@ -54,3 +61,22 @@ func main() {
}
mgr.Cancel()
}
func clearUPass() bool {
if clearPass != "" {
usr := dbService.FindUserName(clearPass)
if usr == nil {
fmt.Printf("user(%s) not found\n", clearPass)
} else {
usr.Pass = ""
_, err := comm.Db.Cols("pass").Where("id=?", usr.Id).Update(usr)
if err != nil {
fmt.Println("clear password err:" + err.Error())
} else {
fmt.Println("clear password ok")
}
}
return true
}
return false
}