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
|
-
|
|
|
|
| 1 | | from turbogears import controllers, expose, flash |
| | 1 | from turbogears import controllers, expose, flash, config |
| 2 | 2 | # from ${package} import model |
| 3 | 3 | #if $sqlobject == 'True' |
| 4 | 4 | import pkg_resources |
| … |
… |
|
| 46 | 46 | |
| 47 | 47 | ${b}expose(template="${package}.templates.login")${e} |
| 48 | 48 | 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 |
| 58 | 57 | 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.") |
| 61 | 64 | 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.") |
| 64 | 68 | 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 |
| 69 | 72 | return dict(message=msg, previous_url=previous_url, logging_in=True, |
| 70 | 73 | original_parameters=request.params, |
| 71 | 74 | forward_url=forward_url) |
-
|
|
|
|
| 1 | | from turbogears import controllers, expose, flash |
| | 1 | from turbogears import controllers, expose, flash, config |
| 2 | 2 | # from ${package} import model |
| 3 | 3 | #if $sqlobject == 'True' |
| 4 | 4 | import pkg_resources |
| … |
… |
|
| 46 | 46 | |
| 47 | 47 | ${b}expose(template="${package}.templates.login")${e} |
| 48 | 48 | 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 |
| 58 | 57 | 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.") |
| 61 | 64 | 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.") |
| 64 | 68 | 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 |
| 69 | 72 | return dict(message=msg, previous_url=previous_url, logging_in=True, |
| 70 | 73 | original_parameters=request.params, |
| 71 | 74 | forward_url=forward_url) |
Download in other formats: