From 4ad8c3c46825481293f38f3ea86d325e78477b86 Mon Sep 17 00:00:00 2001 From: Jordan Date: Sun, 12 Jan 2014 20:00:52 -0600 Subject: [PATCH] Implemented GetUserByAPIKey and changed GetUser to GetUserById --- auth/auth.go | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/auth/auth.go b/auth/auth.go index bb3dc978..45193fca 100644 --- a/auth/auth.go +++ b/auth/auth.go @@ -53,13 +53,27 @@ func Login(r *http.Request) (bool, error) { return true, nil } -func GetUser(id int) (models.User, error) { +func GetUserById(id int) (models.User, error) { u := models.User{} - stmt, err := db.Conn.Prepare("SELECT * FROM Users WHERE id=?") + stmt, err := db.Conn.Prepare("SELECT id, username, apikey FROM Users WHERE id=?") if err != nil { return u, err } - err = stmt.QueryRow(id).Scan(&u.Id, &u.Username, &u.Hash, &u.APIKey) + err = stmt.QueryRow(id).Scan(&u.Id, &u.Username, &u.APIKey) + if err != nil { + //Return false, but don't return an error + return u, err + } + return u, nil +} + +func GetUserByAPIKey(key []byte) (models.User, error) { + u := models.User{} + stmt, err := db.Conn.Prepare("SELECT id, username, apikey FROM Users WHERE apikey=?") + if err != nil { + return u, err + } + err = stmt.QueryRow(key).Scan(&u.Id, &u.Username, &u.APIKey) if err != nil { //Return false, but don't return an error return u, err