mirror of
https://github.com/mindoc-org/mindoc.git
synced 2025-06-28 15:45:35 +08:00
增加命令行修改密码功能
This commit is contained in:
parent
c5fb0c760b
commit
f5737c6a73
@ -230,6 +230,9 @@ func ResolveCommand(args []string) {
|
|||||||
RegisterCache()
|
RegisterCache()
|
||||||
RegisterModel()
|
RegisterModel()
|
||||||
RegisterLogger(conf.LogFile)
|
RegisterLogger(conf.LogFile)
|
||||||
|
|
||||||
|
ModifyPassword()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//注册缓存管道
|
//注册缓存管道
|
||||||
|
@ -8,6 +8,9 @@ import (
|
|||||||
"github.com/astaxie/beego/orm"
|
"github.com/astaxie/beego/orm"
|
||||||
"github.com/lifei6671/mindoc/conf"
|
"github.com/lifei6671/mindoc/conf"
|
||||||
"github.com/lifei6671/mindoc/models"
|
"github.com/lifei6671/mindoc/models"
|
||||||
|
"flag"
|
||||||
|
"github.com/lifei6671/mindoc/utils"
|
||||||
|
"github.com/astaxie/beego"
|
||||||
)
|
)
|
||||||
|
|
||||||
//系统安装.
|
//系统安装.
|
||||||
@ -34,6 +37,61 @@ func Version() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//修改用户密码
|
||||||
|
func ModifyPassword() {
|
||||||
|
var account,password string
|
||||||
|
|
||||||
|
//账号和密码需要解析参数后才能获取
|
||||||
|
if len(os.Args) >= 2 && os.Args[1] == "password" {
|
||||||
|
flagSet := flag.NewFlagSet("MinDoc command: ", flag.ExitOnError)
|
||||||
|
|
||||||
|
flagSet.StringVar(&account, "account", "", "用户账号.")
|
||||||
|
flagSet.StringVar(&password, "password", "", "用户密码.")
|
||||||
|
|
||||||
|
if err := flagSet.Parse(os.Args[2:]); err != nil {
|
||||||
|
beego.Error("解析参数失败 -> ",err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(os.Args) < 2 {
|
||||||
|
fmt.Println("Parameter error.")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
if account == "" {
|
||||||
|
fmt.Println("Account cannot be empty.")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
if password == "" {
|
||||||
|
fmt.Println("Password cannot be empty.")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
member,err := models.NewMember().FindByAccount(account)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Failed to change password:",err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
pwd,err := utils.PasswordHash(password)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Failed to change password:",err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
member.Password = pwd
|
||||||
|
|
||||||
|
err = member.Update("password")
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Failed to change password:",err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
fmt.Println("Successfully modified.")
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
//初始化数据
|
//初始化数据
|
||||||
func initialization() {
|
func initialization() {
|
||||||
|
|
||||||
@ -48,7 +106,7 @@ func initialization() {
|
|||||||
if err == orm.ErrNoRows {
|
if err == orm.ErrNoRows {
|
||||||
|
|
||||||
member.Account = "admin"
|
member.Account = "admin"
|
||||||
member.Avatar = "/static/images/headimgurl.jpg"
|
member.Avatar = conf.URLForWithCdnImage("/static/images/headimgurl.jpg")
|
||||||
member.Password = "123456"
|
member.Password = "123456"
|
||||||
member.AuthMethod = "local"
|
member.AuthMethod = "local"
|
||||||
member.Role = 0
|
member.Role = 0
|
||||||
|
Loading…
Reference in New Issue
Block a user