otfe/misc/test/seed.go

42 lines
1.0 KiB
Go
Raw Normal View History

2022-02-23 12:07:09 +00:00
package main
import (
"git.1248.nz/1248/Otfe/misc/helpers"
"git.1248.nz/1248/Otfe/models"
"github.com/globalsign/mgo/bson"
)
func main() {
models.DBWipeCollection("group", "user", "session")
//admin user and group
adminGroup := models.NewGroup("admin")
adminGroup.Admin = true
adminGroup.ID = bson.NewObjectId()
adminGroup.Permissions["user.show"] = true
admin := models.User{}
admin.Username = "admin"
admin.Email = "admin"
admin.ID = bson.NewObjectId()
admin.Password, _ = helpers.HashPassword("admin")
admin.PrimaryGroup = adminGroup.ID
adminGroup.Users = append(adminGroup.Users, admin.ID)
adminGroup.Create()
admin.Create()
//user and user group
userGroup := models.NewGroup("user")
userGroup.ID = bson.NewObjectId()
userGroup.Admin = false
user := models.User{}
user.ID = bson.NewObjectId()
user.Username = "user"
user.Email = "u"
user.Password, _ = helpers.HashPassword("user")
user.PrimaryGroup = userGroup.ID
userGroup.Users = append(userGroup.Users, user.ID)
user.Create()
userGroup.Create()
}