add global config struct
This commit is contained in:
parent
cc429c44f9
commit
cd1e1a42f3
9 changed files with 251 additions and 214 deletions
31
api/auth.go
31
api/auth.go
|
|
@ -183,3 +183,34 @@ func ResetPassword(cdb *db.ConfigDB) touka.HandlerFunc {
|
|||
AuthLogout(c)
|
||||
}
|
||||
}
|
||||
|
||||
func AuthInitHandle(cdb *db.ConfigDB) touka.HandlerFunc {
|
||||
return func(c *touka.Context) {
|
||||
username := c.PostForm("username")
|
||||
password := c.PostForm("password")
|
||||
// 验证是否为空
|
||||
if username == "" || password == "" {
|
||||
c.JSON(400, touka.H{"error": "username and password are required"})
|
||||
return
|
||||
}
|
||||
// 初始化管理员
|
||||
err := user.InitAdminUser(username, password, cdb)
|
||||
if err != nil {
|
||||
c.JSON(500, touka.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(200, touka.H{"message": "admin initialized"})
|
||||
}
|
||||
}
|
||||
|
||||
func AuthInitStatus() touka.HandlerFunc {
|
||||
return func(c *touka.Context) {
|
||||
// 返回是否init管理员
|
||||
isInit := user.IsAdminInit()
|
||||
if isInit {
|
||||
c.JSON(200, touka.H{"admin_init": true})
|
||||
} else {
|
||||
c.JSON(200, touka.H{"admin_init": false})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue