Implemented GetUserByAPIKey and changed GetUser to GetUserById

pull/24/head
Jordan 2014-01-12 20:00:52 -06:00
parent 2a88b259b3
commit 4ad8c3c468
1 changed files with 17 additions and 3 deletions

View File

@ -53,13 +53,27 @@ func Login(r *http.Request) (bool, error) {
return true, nil return true, nil
} }
func GetUser(id int) (models.User, error) { func GetUserById(id int) (models.User, error) {
u := models.User{} 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 { if err != nil {
return u, err 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 { if err != nil {
//Return false, but don't return an error //Return false, but don't return an error
return u, err return u, err