Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #1628: no_cookie_patch_branch_1_0.patch

File no_cookie_patch_branch_1_0.patch, 5.2 KB (added by chrisz, 4 years ago)

Patch against 1.0 branch

  • turbogears/qstemplates/quickstart/+package+/controllers.py_tmpl

     
    1 from turbogears import controllers, expose, flash 
     1from turbogears import controllers, expose, flash, config 
    22# from ${package} import model 
    33#if $sqlobject == 'True' 
    44import pkg_resources 
     
    4646 
    4747    ${b}expose(template="${package}.templates.login")${e} 
    4848    def login(self, forward_url=None, previous_url=None, *args, **kw): 
    49  
    50         if not identity.current.anonymous \ 
    51             and identity.was_login_attempted() \ 
    52             and not identity.get_identity_errors(): 
    53             raise redirect(forward_url) 
    54  
    55         forward_url=None 
    56         previous_url= request.path 
    57  
     49        cookie_name = config.get("visit.cookie.name", "tg-visit") 
     50        if (not identity.current.anonymous 
     51                and identity.was_login_attempted() 
     52                and not identity.get_identity_errors() 
     53                and request.simple_cookie.has_key(cookie_name)): 
     54            raise redirect(forward_url or request.headers.get("Referer", "/")) 
     55        forward_url = None 
     56        previous_url = request.path 
    5857        if identity.was_login_attempted(): 
    59             msg=_("The credentials you supplied were not correct or " 
    60                    "did not grant access to this resource.") 
     58            if request.simple_cookie.has_key(cookie_name): 
     59                msg = _("The credentials you supplied were not correct" 
     60                    " or did not grant access to this resource.") 
     61            else: 
     62                msg = _("Cannot log in because your browser " 
     63                    " does not support session cookies.") 
    6164        elif identity.get_identity_errors(): 
    62             msg=_("You must provide your credentials before accessing " 
    63                    "this resource.") 
     65            if request.simple_cookie.has_key(cookie_name): 
     66                msg = _("You must provide your credentials" 
     67                       " before accessing this resource.") 
    6468        else: 
    65             msg=_("Please log in.") 
    66             forward_url= request.headers.get("Referer", "/") 
    67  
    68         response.status=403 
     69            msg = _("Please log in.") 
     70            forward_url = request.headers.get("Referer", "/") 
     71        response.status = 403 
    6972        return dict(message=msg, previous_url=previous_url, logging_in=True, 
    7073                    original_parameters=request.params, 
    7174                    forward_url=forward_url) 
  • turbogears/qstemplates/quickstartbig/+package+/controllers/root.py_tmpl

     
    1 from turbogears import controllers, expose, flash 
     1from turbogears import controllers, expose, flash, config 
    22# from ${package} import model 
    33#if $sqlobject == 'True' 
    44import pkg_resources 
     
    4646 
    4747    ${b}expose(template="${package}.templates.login")${e} 
    4848    def login(self, forward_url=None, previous_url=None, *args, **kw): 
    49  
    50         if not identity.current.anonymous \ 
    51             and identity.was_login_attempted() \ 
    52             and not identity.get_identity_errors(): 
    53             raise redirect(forward_url) 
    54  
    55         forward_url=None 
    56         previous_url= request.path 
    57  
     49        cookie_name = config.get("visit.cookie.name", "tg-visit") 
     50        if (not identity.current.anonymous 
     51                and identity.was_login_attempted() 
     52                and not identity.get_identity_errors() 
     53                and request.simple_cookie.has_key(cookie_name)): 
     54            raise redirect(forward_url or request.headers.get("Referer", "/")) 
     55        forward_url = None 
     56        previous_url = request.path 
    5857        if identity.was_login_attempted(): 
    59             msg=_("The credentials you supplied were not correct or " 
    60                    "did not grant access to this resource.") 
     58            if request.simple_cookie.has_key(cookie_name): 
     59                msg = _("The credentials you supplied were not correct" 
     60                    " or did not grant access to this resource.") 
     61            else: 
     62                msg = _("Cannot log in because your browser " 
     63                    " does not support session cookies.") 
    6164        elif identity.get_identity_errors(): 
    62             msg=_("You must provide your credentials before accessing " 
    63                    "this resource.") 
     65            if request.simple_cookie.has_key(cookie_name): 
     66                msg = _("You must provide your credentials" 
     67                       " before accessing this resource.") 
    6468        else: 
    65             msg=_("Please log in.") 
    66             forward_url= request.headers.get("Referer", "/") 
    67  
    68         response.status=403 
     69            msg = _("Please log in.") 
     70            forward_url = request.headers.get("Referer", "/") 
     71        response.status = 403 
    6972        return dict(message=msg, previous_url=previous_url, logging_in=True, 
    7073                    original_parameters=request.params, 
    7174                    forward_url=forward_url)