tg.request.identity

Here are the examples of the python api tg.request.identity taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

2 Examples 7

Example 1

Project: SAUCE Source File: root.py
Function: post_login
    @expose()
    def post_login(self, came_from=lurl('/'), *args, **kwargs):
        """
        Redirect the user to the initially requested page on successful
        authentication or redirect her back to the login page if login failed.

        """
        if not request.identity:
            login_counter = request.environ.get('repoze.who.logins', 0) + 1
            redirect('/login',
                params=dict(came_from=came_from, __logins=login_counter))
        user = request.user
        flash(_('Welcome back, %s!') % user.display_name)
        # Do not use tg.redirect with tg.url as it will add the mountpoint
        # of the application twice.
        return HTTPFound(location=str(came_from))

Example 2

Project: SAUCE Source File: base.py
Function: call
    def __call__(self, environ, context):
        """Invoke the Controller"""
        # TGController.__call__ dispatches to the Controller method
        # the request is routed to.

        # Fill tmpl_context with user data for convenience
        request.identity = c.identity = environ.get('repoze.who.identity')

        try:
            request.user = model.DBSession.merge(request.identity.get('user'))
        except:
            request.user = None
        finally:
            try:
                request.permissions = request.identity.get('permissions')
            except AttributeError:
                request.permissions = []
            request.student = request.user
            request.teacher = request.user
            c.user = request.user
            c.student = request.user
            c.teacher = request.user

        request.referer = request.environ.get('HTTP_REFERER', None)

        request.allowance = _allowance

        # Initialize other tmpl_context variables
        c.sub_menu = []
        c.side_menu = []

        doc_list = list([('About', lurl('/about'), 'info-sign'), None] +
            list((label, lurl('/docs/' + url), 'book') for label, url in (
                ('Changelog', 'Changelog'),
                ('Roadmap', 'Roadmap'),
                ('Deutsche Dokumentation', 'deutsch'),
                ('Tips and Tricks', 'tips'),
                ('Test configuration', 'tests'),
            )) + [None, ('Language information', '/languages', 'list-alt')])

        c.doc_menu = menu_docs(doc_list)

        c.event_menu = menu_events(Event.current_events(), Event.future_events(), Event.previous_events())

        return super(BaseController, self).__call__(environ, context)