Refactor vote validation method

And make it work with AJAX code (from HTML pages) and API code (from the RESTful webservice).