cubicweb/web/views/basecontrollers.py
changeset 12567 26744ad37953
parent 12503 b01dd0ef43aa
child 12912 3966f09d5f5c
equal deleted inserted replaced
12566:6b3523f81f42 12567:26744ad37953
    17 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
    17 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
    18 """Set of base controllers, which are directly plugged into the application
    18 """Set of base controllers, which are directly plugged into the application
    19 object to handle publication.
    19 object to handle publication.
    20 """
    20 """
    21 
    21 
    22 from six import text_type
    22 import http.client
    23 from six.moves import http_client
       
    24 
    23 
    25 from cubicweb import (NoSelectableObject, ObjectNotFound, ValidationError,
    24 from cubicweb import (NoSelectableObject, ObjectNotFound, ValidationError,
    26                       AuthenticationError, UndoTransactionException,
    25                       AuthenticationError, UndoTransactionException,
    27                       Forbidden)
    26                       Forbidden)
    28 from cubicweb.utils import json_dumps
    27 from cubicweb.utils import json_dumps
    42         if self._cw.vreg.config['auth-mode'] == 'http':
    41         if self._cw.vreg.config['auth-mode'] == 'http':
    43             # HTTP authentication
    42             # HTTP authentication
    44             raise AuthenticationError()
    43             raise AuthenticationError()
    45         else:
    44         else:
    46             # Cookie authentication
    45             # Cookie authentication
    47             self._cw.status_out = http_client.FORBIDDEN
    46             self._cw.status_out = http.client.FORBIDDEN
    48             return self.appli.need_login_content(self._cw)
    47             return self.appli.need_login_content(self._cw)
    49 
    48 
    50 class LoginControllerForAuthed(Controller):
    49 class LoginControllerForAuthed(Controller):
    51     __regid__ = 'login'
    50     __regid__ = 'login'
    52     __select__ = ~anonymous_user()
    51     __select__ = ~anonymous_user()
   185                 ctrl._edited_entity.complete()
   184                 ctrl._edited_entity.complete()
   186             return (True, ex.location, ctrl._edited_entity)
   185             return (True, ex.location, ctrl._edited_entity)
   187     except Exception as ex:
   186     except Exception as ex:
   188         req.cnx.rollback()
   187         req.cnx.rollback()
   189         req.exception('unexpected error while validating form')
   188         req.exception('unexpected error while validating form')
   190         return (False, text_type(ex), ctrl._edited_entity)
   189         return (False, str(ex), ctrl._edited_entity)
   191     return (False, '???', None)
   190     return (False, '???', None)
   192 
   191 
   193 
   192 
   194 class FormValidatorController(Controller):
   193 class FormValidatorController(Controller):
   195     __regid__ = 'validateform'
   194     __regid__ = 'validateform'