コード例 #1
0
// 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)
}
コード例 #2
0
// 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)
}
コード例 #3
0
// 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)
}