Append user object to request object. from pyramid.decorator import reify from pyramid.request import Request from pyramid.security import unauthenticated_userid class RequestWithUserAttribute(Request): @reify def user(self): userid = unauthenticated_userid(self) if userid is not None: return Users.by_id(userid)
def main(global_config, **settings): config.set_request_factory(RequestWithUserAttribute) def login(request): if request.user: # User is logged in already so redirect else: # Handle the login provide login form On Mon, Sep 26, 2011 at 11:36 AM, Benjamin Sims <benjamins...@gmail.com>wrote: > That is, a way to check that a user is not authenticated in order to > restrict access to a login form? > > I understand that I can do redirects in the view or remove elements in the > template depending on whether there is a user set, just wondering if there > is a way to do it at the route config level. > > Thanks, > Ben > > -- > You received this message because you are subscribed to the Google Groups > "pylons-discuss" group. > To post to this group, send email to pylons-discuss@googlegroups.com. > To unsubscribe from this group, send email to > pylons-discuss+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/pylons-discuss?hl=en. > -- -- Regards, Bruce Wade http://ca.linkedin.com/in/brucelwade http://www.wadecybertech.com http://www.warplydesigned.com http://www.fitnessfriendsfinder.com -- You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To post to this group, send email to pylons-discuss@googlegroups.com. To unsubscribe from this group, send email to pylons-discuss+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en.