GraphQL API and utilities for the rpdata project
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

34 lines
577 B

package users
import (
"git.aiterp.net/rpdata/api/models"
"github.com/globalsign/mgo"
)
// Ensure finds a user by id, or makes a new one.
func Ensure(id string) (models.User, error) {
user := models.User{}
err := collection.FindId(id).One(&user)
if err == mgo.ErrNotFound {
user = models.User{
ID: id,
Nick: "",
Permissions: []string{
"member",
"log.edit",
"post.edit",
"post.move",
"post.remove",
"file.upload",
},
}
err := collection.Insert(user)
if err != nil {
return models.User{}, err
}
}
return user, err
}