// AddUserPublicKey adds a public key to a user's saved key list func AddUserPublicKey(userId, name, value string) error { pubKey := user.PubKey{ Name: name, Key: value, CreatedAt: time.Now(), } selector := bson.M{ user.IdKey: userId, fmt.Sprintf("%s.%s", user.PubKeysKey, user.PubKeyNameKey): bson.M{"$ne": pubKey.Name}, } update := bson.M{ "$push": bson.M{ user.PubKeysKey: pubKey, }, } return user.UpdateOne(selector, update) }
// SetUserAPIKey updates the API key stored with a user. func SetUserAPIKey(userId, newKey string) error { update := bson.M{"$set": bson.M{user.APIKeyKey: newKey}} return user.UpdateOne(bson.M{user.IdKey: userId}, update) }
// SaveUserSettings updates the settings stored for the given user id. func SaveUserSettings(userId string, settings user.UserSettings) error { update := bson.M{"$set": bson.M{user.SettingsKey: settings}} return user.UpdateOne(bson.M{user.IdKey: userId}, update) }