package setup

import (
	"gitlab.thpeetz.de/kontor/kontor-go/pkg/admin"
	"gitlab.thpeetz.de/kontor/kontor-go/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.KontorDb}
	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)
	}
}
