use tween to centralize redirection or something else

37 views
Skip to first unread message

jerry

unread,
Apr 8, 2013, 7:18:53 AM4/8/13
to pylons-discuss
This is what I want to achieve --

Previously users signup with their email address, follow the link in
the confirmation email to complete the signup. Now I want to allow
them to GET everything before confirming their email, but when they
POST to anything, they will be redirected to a page telling them to
confirm email first.

I don't find it fit the authorization realm and tried with the tween
approach, but soon realize building a complete response object without
using the handler can be messy.

What would be the best practice to achieve this?

Thanks.

Jerry

Jonathan Vanasco

unread,
Apr 8, 2013, 11:18:32 AM4/8/13
to pylons-discuss
are you using Pyramid's auth already ?

Jerry

unread,
Apr 8, 2013, 12:31:27 PM4/8/13
to pylons-...@googlegroups.com
I am already using Pyramid auth, but to bend it for the new feature I'd have to edit _every_ add_view(), which will make it an even worse hack than my current tween hack, where I need to manually recreate the attributes used in the template, notably the missing matched_route --

def signup_hack_tween_factory(handler, registry):
    def signup_hack_tween(request):
        if request.user and not request.user.user_name and request.method == 'POST':
            request.c['h'] = helpers
            request.matched_route = Mock()
            settings = registry.settings
            request.RedisCache = settings['RedisCache']
            return render_to_response('templates/signup_hack.genshi', request.c, request)
        else:
            try:
                response = handler(request)
            finally:
                return response

    return signup_hack_tween


Jerry
Reply all
Reply to author
Forward
0 new messages