mirror of
https://github.com/AlistGo/alist.git
synced 2025-06-04 00:53:19 +08:00
feat: initial setting items
This commit is contained in:
54
internal/bootstrap/data/user.go
Normal file
54
internal/bootstrap/data/user.go
Normal file
@ -0,0 +1,54 @@
|
||||
package data
|
||||
|
||||
import (
|
||||
"github.com/alist-org/alist/v3/cmd/args"
|
||||
"github.com/alist-org/alist/v3/internal/db"
|
||||
"github.com/alist-org/alist/v3/internal/model"
|
||||
"github.com/alist-org/alist/v3/pkg/utils/random"
|
||||
"github.com/pkg/errors"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func initUser() {
|
||||
admin, err := db.GetAdmin()
|
||||
adminPassword := random.String(8)
|
||||
if args.Dev {
|
||||
adminPassword = "admin"
|
||||
}
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
admin = &model.User{
|
||||
Username: "admin",
|
||||
Password: adminPassword,
|
||||
Role: model.ADMIN,
|
||||
BasePath: "/",
|
||||
Webdav: true,
|
||||
}
|
||||
if err := db.CreateUser(admin); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
} else {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
guest, err := db.GetGuest()
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
guest = &model.User{
|
||||
Username: "guest",
|
||||
Password: "guest",
|
||||
ReadOnly: true,
|
||||
Webdav: true,
|
||||
Role: model.GUEST,
|
||||
BasePath: "/",
|
||||
}
|
||||
if err := db.CreateUser(guest); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
} else {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
log.Infof("admin password: %+v", admin.Password)
|
||||
}
|
Reference in New Issue
Block a user