added db function to see if user exists
This commit is contained in:
parent
b99cae7a2e
commit
5c26150d98
26
db.go
26
db.go
@ -312,3 +312,29 @@ func (db *DB) addUser(email string) (string, error) {
|
||||
)
|
||||
return tok, err
|
||||
}
|
||||
|
||||
func (db *DB) hasUser(email string) error {
|
||||
result, err := db.conn.Query(
|
||||
"SELECT EXISTS(SELECT 1 FROM users WHERE email = ? LIMIT 1)",
|
||||
email,
|
||||
)
|
||||
if err != nil {
|
||||
return verrors.HTTP{
|
||||
Message: fmt.Sprintf("could not find requested user's email: %q: %v", email, err),
|
||||
Code: http.StatusInternalServerError,
|
||||
}
|
||||
}
|
||||
var exists string
|
||||
for result.Next() {
|
||||
if err := result.Scan(&exists); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
if exists == "0" {
|
||||
return verrors.HTTP{
|
||||
Message: fmt.Sprintf("could not find requested user's email: %q: %v", email, err),
|
||||
Code: http.StatusInternalServerError,
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user