Add support for authentication using AJAX

* return 400 (Bad Request) in case of failure, and return all of current
  validation as JSON.
* return 200 (OK) in case of success, and return the redirect URL as
  JSON.