feat: first time admin user creation through the ui

This commit is contained in:
Deluan 2020-01-25 17:10:16 -05:00
parent b4c95fa8db
commit 58a7879ba8
9 changed files with 301 additions and 147 deletions

View file

@ -1,10 +1,8 @@
package server
import (
"fmt"
"time"
"github.com/deluan/navidrome/conf"
"github.com/deluan/navidrome/consts"
"github.com/deluan/navidrome/log"
"github.com/deluan/navidrome/model"
@ -18,9 +16,6 @@ func initialSetup(ds model.DataStore) {
return nil
}
log.Warn("Running initial setup")
if err = createDefaultUser(ds); err != nil {
return err
}
if err = createJWTSecret(ds); err != nil {
return err
}
@ -43,32 +38,3 @@ func createJWTSecret(ds model.DataStore) error {
}
return err
}
func createDefaultUser(ds model.DataStore) error {
c, err := ds.User().CountAll()
if err != nil {
panic(fmt.Sprintf("Could not access User table: %s", err))
}
if c == 0 {
id, _ := uuid.NewRandom()
random, _ := uuid.NewRandom()
initialPassword := random.String()
if conf.Server.DevInitialPassword != "" {
initialPassword = conf.Server.DevInitialPassword
}
log.Warn("Creating initial user. Please change the password!", "user", consts.InitialUserName, "password", initialPassword)
initialUser := model.User{
ID: id.String(),
UserName: consts.InitialUserName,
Name: consts.InitialName,
Email: "",
Password: initialPassword,
IsAdmin: true,
}
err := ds.User().Put(&initialUser)
if err != nil {
log.Error("Could not create initial user", "user", initialUser, err)
}
}
return err
}