func (c *C) Insert(a iface.Filter, data map[string]interface{}) error { m, err := c.decrypt(data) if err != nil { return err } m["created"] = time.Now().UnixNano() // Should include user too maybe. return a.Insert(m) }
func RegisterUser(a iface.Filter, user map[string]interface{}) (bson.ObjectId, error) { user["password"] = hashPass(user["password"].(string)) if _, has := user["level"]; !has { user["level"] = 100 } user_id := bson.NewObjectId() user["_id"] = user_id err := a.Insert(user) if err != nil { return "", fmt.Errorf("Name is not unique.") } return user_id, nil }
func (b *Basics) Insert(a iface.Filter, data map[string]interface{}) (bson.ObjectId, error) { id := bson.NewObjectId() data["_id"] = id err := a.Insert(data) if err != nil { return "", err } if b.Ev != nil { q := map[string]interface{}{ "_id": id, } filt := a.Clone().AddQuery(q) b.Ev.Fire("Inserted", filt) b.Ev.Fire(a.Subject()+"Inserted", filt) } return id, nil }