// Finds a user by id. func FindUser(a iface.Filter, id bson.ObjectId) (map[string]interface{}, error) { q := m{"_id": id} v, err := a.AddQuery(q).FindOne() if err != nil { return nil, err } delete(v, "password") return v, nil }
// Finds he user by name password equality. func namePass(a iface.Filter, name, encoded_pass string) (map[string]interface{}, error) { q := bson.M{ "name": name, "password": encoded_pass, } doc, err := a.AddQuery(q).FindOne() if err != nil { return nil, err } return convert.Clean(doc).(map[string]interface{}), nil }
// Returns true if the username is still available. func NameAvailable(a iface.Filter, name string) (bool, error) { q := bson.M{"slug": slugify.S(name)} users, err := a.AddQuery(q).Find() if err != nil { return false, err } if len(users) > 0 { return false, nil } return true, nil }
func hasAdmin(f iface.Filter) error { q := map[string]interface{}{ "level": 300, } f.AddQuery(q) c, err := f.Count() if err != nil { return err } if c > 0 { return fmt.Errorf("Site already has an admin.") } return nil }