summary refs log tree commit diff stats
path: root/auth/token/validate.go
diff options
context:
space:
mode:
authorAndinus <andinus@nand.sh>2020-03-28 19:25:53 +0530
committerAndinus <andinus@nand.sh>2020-03-28 19:25:53 +0530
commit7b95d6b80dd2d1efb26f7c515383abd4f0dc9d42 (patch)
tree76dca236dc2d7c3be989896442cb3edfa1235e8d /auth/token/validate.go
parentb0b83af1c45c2d5ee587dc96847e25c95a3d50b0 (diff)
downloadperseus-7b95d6b80dd2d1efb26f7c515383abd4f0dc9d42.tar.gz
Prepare for rewrite on several functions
User struct now exports everything, encapsulation is not necessary
over here. Instead of introducing a new variable uInfo we'll use
user.User and pass that. Handlers & related functions will be
rewritten to work with this change. This will make it easier to work
on later as the program grows. I'm also rethinking error handling.
Diffstat (limited to 'auth/token/validate.go')
-rw-r--r--auth/token/validate.go51
1 files changed, 0 insertions, 51 deletions
diff --git a/auth/token/validate.go b/auth/token/validate.go
deleted file mode 100644
index f1ee149..0000000
--- a/auth/token/validate.go
+++ /dev/null
@@ -1,51 +0,0 @@
-package token
-
-import (
-	"errors"
-	"log"
-
-	"tildegit.org/andinus/perseus/storage/sqlite3"
-	"tildegit.org/andinus/perseus/user"
-)
-
-// ValToken will validate the token and returns an error. If error
-// doesn't equal nil then consider token invalid.
-func ValToken(db *sqlite3.DB, uInfo map[string]string) error {
-	// Acquire read lock on the database.
-	db.Mu.RLock()
-	defer db.Mu.RUnlock()
-
-	u := user.User{}
-	u.SetUsername(uInfo["username"])
-
-	// Set user id from username.
-	err := u.GetID(db)
-	if err != nil {
-		log.Printf("auth/token.go: %s\n",
-			"failed to get id from username")
-		return err
-	}
-
-	// Check if user's token is valid.
-	stmt, err := db.Conn.Prepare("SELECT token FROM access WHERE id = ?")
-	if err != nil {
-		log.Printf("auth/token.go: %s\n",
-			"failed to prepare statement")
-		return err
-	}
-	defer stmt.Close()
-
-	var token string
-	err = stmt.QueryRow(u.ID()).Scan(&token)
-	if err != nil {
-		log.Printf("auth/token.go: %s\n",
-			"query failed")
-		return err
-	}
-
-	if token != uInfo["token"] {
-		err = errors.New("token mismatch")
-	}
-
-	return err
-}