aboutsummaryrefslogtreecommitdiffhomepage
path: root/storage
diff options
context:
space:
mode:
authorGravatar Frédéric Guillot <fred@miniflux.net>2017-12-29 14:38:43 -0800
committerGravatar Frédéric Guillot <fred@miniflux.net>2017-12-29 14:38:43 -0800
commit038ea790f76243b7e08119438bed24a37d452cb7 (patch)
tree0f6f089bd7f22e33b0ef18ab446256bee4bff309 /storage
parent9eb91e6f0b175a1e96fd252924a52261ee595ba8 (diff)
Make sure people don't create duplicate Fever usernames
Diffstat (limited to 'storage')
-rw-r--r--storage/integration.go16
1 files changed, 15 insertions, 1 deletions
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