Beispiel #1
0
func (m *UserManager) Update(obj *user.User) error {
	obj.Updated = time.Now().UTC()
	if obj.Avatar == "" {
		obj.Avatar = utils.GetGravatar(obj.Email, 38, utils.AvatarRetro)
	}
	if obj.Nickname == "" {
		obj.Nickname = strings.Split(obj.Email, "@")[0]
	}
	return m.col.UpdateId(obj.Id, obj)
}
Beispiel #2
0
func (m *UserManager) Create(raw *user.User) (*user.User, error) {
	// TODO (m0sth8): add validation
	raw.Id = bson.NewObjectId()
	raw.Created = time.Now().UTC()
	raw.Updated = raw.Created
	raw.Avatar = utils.GetGravatar(raw.Email, 38, utils.AvatarRetro)
	if raw.Nickname == "" {
		raw.Nickname = strings.Split(raw.Email, "@")[0]
	}

	if err := m.col.Insert(raw); err != nil {
		return nil, err
	}
	return raw, nil
}