Added tests for roundtrip and register #4
26
db.go
26
db.go
@ -312,3 +312,29 @@ func (db *DB) addUser(email string) (string, error) {
|
|||||||
)
|
)
|
||||||
return tok, err
|
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