From a827a6e91bf981f794b3d74ff5cfd651810e3874 Mon Sep 17 00:00:00 2001 From: Joerg Lehmann Date: Sun, 2 Oct 2022 16:19:12 +0200 Subject: [PATCH] add some validation code --- persistence.go | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/persistence.go b/persistence.go index e8827f1..045da29 100644 --- a/persistence.go +++ b/persistence.go @@ -119,15 +119,14 @@ func checkUserAvailable(username string) bool { conn := globalPool.Get() defer conn.Close() - _, err := conn.Do("HGETALL", userPrefix+username) - if err == redis.ErrNil { - logit("User does not exist and is therefore available:" + username) + exists, _ := redis.Bool(conn.Do("EXISTS", userPrefix+username)) + if !exists { + logit("checkUserAvailable: User does not exist, so it is available: " + username) return true - } else if err != nil { - logit("checkUserAvailable: Error to query Key Value Store") + } else { + logit("checkUserAvailable: User exist, so it is not available: " + username) return false } - return false } func getMyDevs(username string) []string { @@ -363,10 +362,10 @@ func updateUser(username, password string) { defer conn.Close() logit("updateUser: " + username) - // we exit if user does not exit + // we exit if user does not exit exists, _ := redis.Bool(conn.Do("EXISTS", userPrefix+username)) if !exists { - logit("updateUser: User does not exist: " + username) + logit("updateUser: User does not exist: " + username) return }