2017-01-25 16:11:35 +00:00
|
|
|
package datastore
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/dannyvankooten/ana/models"
|
|
|
|
)
|
|
|
|
|
|
|
|
var u models.User
|
|
|
|
|
2017-01-25 19:01:02 +00:00
|
|
|
// GetUser retrieves user from datastore by its ID
|
2017-01-25 16:11:35 +00:00
|
|
|
func GetUser(id int64) (*models.User, error) {
|
|
|
|
stmt, err = DB.Prepare("SELECT id, email FROM users WHERE id = ? LIMIT 1")
|
|
|
|
err = stmt.QueryRow(id).Scan(&u.ID, &u.Email)
|
|
|
|
return &u, err
|
|
|
|
}
|
|
|
|
|
2017-01-25 19:01:02 +00:00
|
|
|
// GetUserByEmail retrieves user from datastore by its email
|
2017-01-25 16:11:35 +00:00
|
|
|
func GetUserByEmail(email string) (*models.User, error) {
|
|
|
|
stmt, err = DB.Prepare("SELECT id, email, password FROM users WHERE email = ? LIMIT 1")
|
2017-01-25 19:01:02 +00:00
|
|
|
err = stmt.QueryRow(email).Scan(&u.ID, &u.Email, &u.HashedPassword)
|
2017-01-25 16:11:35 +00:00
|
|
|
return &u, err
|
|
|
|
}
|