@view_config(request_param='__formid__=login')
    def login(self):
        try:
            json_body = self.request.json_body
        except __HOLE__ as err:
            raise accounts.JSONError(
                _('Could not parse request body as JSON: {message}'.format(
                    message=err.message)))

        if not isinstance(json_body, dict):
            raise accounts.JSONError(
                _('Request JSON body must have a top-level object'))

        # Transform non-string usernames and password into strings.
        # Deform crashes otherwise.
        json_body['username'] = unicode(json_body.get('username') or '')
        json_body['password'] = unicode(json_body.get('password') or '')

        appstruct = self.form.validate(json_body.items())

        user = appstruct['user']
        headers = self._login(user)
        self.request.response.headers.extend(headers)

        return ajax_payload(self.request, {'status': 'okay'})
dataset/ETHPy150Open hypothesis/h/h/accounts/views.py/AjaxAuthController.login