2018-05-27 22:40:42 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import ()
|
|
|
|
|
|
|
|
func ownerGetByEmail(email string) (owner, error) {
|
|
|
|
if email == "" {
|
|
|
|
return owner{}, errorMissingField
|
|
|
|
}
|
|
|
|
|
|
|
|
statement := `
|
|
|
|
SELECT ownerHex, email, name, confirmedEmail, joinDate
|
|
|
|
FROM owners
|
|
|
|
WHERE email=$1;
|
|
|
|
`
|
|
|
|
row := db.QueryRow(statement, email)
|
|
|
|
|
|
|
|
var o owner
|
|
|
|
if err := row.Scan(&o.OwnerHex, &o.Email, &o.Name, &o.ConfirmedEmail, &o.JoinDate); err != nil {
|
|
|
|
// TODO: Make sure this is actually no such email.
|
|
|
|
return owner{}, errorNoSuchEmail
|
|
|
|
}
|
|
|
|
|
|
|
|
return o, nil
|
|
|
|
}
|
|
|
|
|
2018-06-20 11:29:55 +08:00
|
|
|
func ownerGetByOwnerToken(ownerToken string) (owner, error) {
|
|
|
|
if ownerToken == "" {
|
2018-05-27 22:40:42 +08:00
|
|
|
return owner{}, errorMissingField
|
|
|
|
}
|
|
|
|
|
|
|
|
statement := `
|
|
|
|
SELECT ownerHex, email, name, confirmedEmail, joinDate
|
|
|
|
FROM owners
|
2018-10-18 12:56:56 +08:00
|
|
|
WHERE ownerHex IN (
|
|
|
|
SELECT ownerHex FROM ownerSessions
|
2018-06-20 11:29:55 +08:00
|
|
|
WHERE ownerToken = $1
|
2018-05-27 22:40:42 +08:00
|
|
|
);
|
|
|
|
`
|
2018-06-20 11:29:55 +08:00
|
|
|
row := db.QueryRow(statement, ownerToken)
|
2018-05-27 22:40:42 +08:00
|
|
|
|
|
|
|
var o owner
|
|
|
|
if err := row.Scan(&o.OwnerHex, &o.Email, &o.Name, &o.ConfirmedEmail, &o.JoinDate); err != nil {
|
|
|
|
logger.Errorf("cannot scan owner: %v\n", err)
|
|
|
|
return owner{}, errorInternal
|
|
|
|
}
|
|
|
|
|
|
|
|
return o, nil
|
|
|
|
}
|