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.
33 lines
558 B
33 lines
558 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",
|
|
"file.upload",
|
|
},
|
|
}
|
|
|
|
err := collection.Insert(user)
|
|
if err != nil {
|
|
return models.User{}, err
|
|
}
|
|
}
|
|
|
|
return user, err
|
|
}
|