api: replace commenterIsProviderUser
This commit is contained in:
parent
2f93726a04
commit
d75c882882
@ -13,26 +13,3 @@ type commenter struct {
|
|||||||
Provider string `json:"provider,omitempty"`
|
Provider string `json:"provider,omitempty"`
|
||||||
JoinDate time.Time `json:"joinDate,omitempty"`
|
JoinDate time.Time `json:"joinDate,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func commenterIsProviderUser(provider string, email string) (bool, error) {
|
|
||||||
if provider == "" || email == "" {
|
|
||||||
return false, errorMissingField
|
|
||||||
}
|
|
||||||
|
|
||||||
statement := `
|
|
||||||
SELECT EXISTS (
|
|
||||||
SELECT 1
|
|
||||||
FROM commenters
|
|
||||||
WHERE email=$1 AND provider=$2
|
|
||||||
);
|
|
||||||
`
|
|
||||||
row := db.QueryRow(statement, email, provider)
|
|
||||||
|
|
||||||
var exists bool
|
|
||||||
if err := row.Scan(&exists); err != nil {
|
|
||||||
logger.Errorf("error checking if provider user exists: %v", err)
|
|
||||||
return false, errorInternal
|
|
||||||
}
|
|
||||||
|
|
||||||
return exists, nil
|
|
||||||
}
|
|
||||||
|
@ -23,6 +23,27 @@ func commenterGetByHex(commenterHex string) (commenter, error) {
|
|||||||
return c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func commenterGetByEmail(provider string, email string) (commenter, error) {
|
||||||
|
if provider == "" || email == "" {
|
||||||
|
return commenter{}, errorMissingField
|
||||||
|
}
|
||||||
|
|
||||||
|
statement := `
|
||||||
|
SELECT commenterHex, email, name, link, photo, provider, joinDate
|
||||||
|
FROM commenters
|
||||||
|
WHERE email = $1 AND provider = $2;
|
||||||
|
`
|
||||||
|
row := db.QueryRow(statement, email, provider)
|
||||||
|
|
||||||
|
c := commenter{}
|
||||||
|
if err := row.Scan(&c.CommenterHex, &c.Email, &c.Name, &c.Link, &c.Photo, &c.Provider, &c.JoinDate); err != nil {
|
||||||
|
// TODO: is this the only error?
|
||||||
|
return commenter{}, errorNoSuchCommenter
|
||||||
|
}
|
||||||
|
|
||||||
|
return c, nil
|
||||||
|
}
|
||||||
|
|
||||||
func commenterGetBySession(session string) (commenter, error) {
|
func commenterGetBySession(session string) (commenter, error) {
|
||||||
if session == "" {
|
if session == "" {
|
||||||
return commenter{}, errorMissingField
|
return commenter{}, errorMissingField
|
||||||
|
Loading…
Reference in New Issue
Block a user