Check that affiliate is valid in was_referred() to fix #282