From 038ea790f76243b7e08119438bed24a37d452cb7 Mon Sep 17 00:00:00 2001 From: Frédéric Guillot Date: Fri, 29 Dec 2017 14:38:43 -0800 Subject: Make sure people don't create duplicate Fever usernames --- storage/integration.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'storage') diff --git a/storage/integration.go b/storage/integration.go index 779ca81..aacb520 100644 --- a/storage/integration.go +++ b/storage/integration.go @@ -11,11 +11,25 @@ import ( "github.com/miniflux/miniflux/model" ) +// HasDuplicateFeverUsername checks if another user have the same fever username. +func (s *Storage) HasDuplicateFeverUsername(userID int64, feverUsername string) bool { + query := ` + SELECT + count(*) as c + FROM integrations + WHERE user_id != $1 AND fever_username=$2 + ` + + var result int + s.db.QueryRow(query, userID, feverUsername).Scan(&result) + return result >= 1 +} + // UserByFeverToken returns a user by using the Fever API token. func (s *Storage) UserByFeverToken(token string) (*model.User, error) { query := ` SELECT - users.id, users.is_admin, users.timezone + users.id, users.is_admin, users.timezone FROM users LEFT JOIN integrations ON integrations.user_id=users.id WHERE integrations.fever_enabled='t' AND integrations.fever_token=$1 -- cgit v1.2.3