Added tests for roundtrip and register #4

Closed
dm wants to merge 3 commits from dm/email into email
Showing only changes of commit 5c26150d98 - Show all commits

26
db.go
View File

@ -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
}