Files
2022-02-15 14:21:23 +00:00

21 lines
609 B
Go

package setup
import (
"gitlab.thpeetz.de/domain-thpeetz/kalorienmanager.git/pkg/admin"
"gitlab.thpeetz.de/domain-thpeetz/kalorienmanager.git/pkg/dao"
"gopkg.in/mgo.v2/bson"
)
// CheckUserList ensures that at least the admin user is available.
func CheckUserList() {
var userDao = admin.UserDAO{Db: dao.KalorienmanagerDb}
users, err := userDao.FindAll()
if err == nil && len(users) == 0 {
password, _ := admin.HashPassword("admin")
id := bson.NewObjectId()
user := admin.User{ID: id, Username: "admin", Password: password, Firstname: "Administrator", IsAdmin: true}
userDao.Insert(user)
}
}