Beispiel #1
0
def auth_force_logout():
    """Forces user logout if authentication is enabled."""
    req = request._current_obj()
    resp = response._current_obj()

    api = req.environ.get('repoze.who.api')
    if api:
        resp.headers.extend(api.forget())
Beispiel #2
0
def auth_force_logout():
    """Forces user logout if authentication is enabled."""
    req = request._current_obj()
    resp = response._current_obj()

    api = req.environ.get('repoze.who.api')
    if api:
        resp.headers.extend(api.forget())
Beispiel #3
0
    def __call__(self, message, status=None, **extra_payload):
        """Registers a flash message for display on current or next request."""
        # Force the message to be unicode so lazystrings, etc... are coerced
        message = unicode_text(message)

        payload = self._prepare_payload(message=message, status=status or self.default_status, **extra_payload)

        if request is not None:
            # Save the payload in environ too in case JavaScript is not being
            # used and the message is being displayed in the same request.
            request.environ["webflash.payload"] = payload

        resp = response._current_obj()
        resp.set_cookie(self.cookie_name, payload)
        if len(resp.headers["Set-Cookie"]) > 4096:
            raise ValueError("Flash value is too long (cookie would be >4k)")
Beispiel #4
0
    def __call__(self, message, status=None, **extra_payload):
        """Registers a flash message for display on current or next request."""
        # Force the message to be unicode so lazystrings, etc... are coerced
        message = unicode_text(message)

        payload = self._prepare_payload(message=message,
                                        status=status or self.default_status,
                                        **extra_payload)

        if request is not None:
            # Save the payload in environ too in case JavaScript is not being
            # used and the message is being displayed in the same request.
            request.environ['webflash.payload'] = payload

        resp = response._current_obj()
        resp.set_cookie(self.cookie_name, payload)
        if len(resp.headers['Set-Cookie']) > 4096:
            raise ValueError('Flash value is too long (cookie would be >4k)')
Beispiel #5
0
def auth_force_login(user_name):
    """Forces user login if authentication is enabled.

    As TurboGears identifies users by ``user_name`` the passed parameter should
    be anything your application declares being the ``user_name`` field in models.

    """
    req = request._current_obj()
    resp = response._current_obj()

    api = req.environ.get("repoze.who.api")
    if api:
        authentication_plugins = req.environ["repoze.who.plugins"]
        try:
            identifier = authentication_plugins["main_identifier"]
        except KeyError:
            raise TGConfigError('No repoze.who plugin registered as "main_identifier"')

        resp.headers.extend(api.remember({"repoze.who.userid": user_name, "identifier": identifier}))
Beispiel #6
0
def auth_force_login(user_name):
    """Forces user login if authentication is enabled.

    As TurboGears identifies users by ``user_name`` the passed parameter should
    be anything your application declares being the ``user_name`` field in models.

    """
    req = request._current_obj()
    resp = response._current_obj()

    api = req.environ.get('repoze.who.api')
    if api:
        authentication_plugins = req.environ['repoze.who.plugins']
        try:
            identifier = authentication_plugins['main_identifier']
        except KeyError:
            raise TGConfigError('No repoze.who plugin registered as "main_identifier"')

        resp.headers.extend(api.remember({
            'repoze.who.userid': user_name,
            'identifier': identifier
        }))