| 30 | # Light security check -- make sure redirect_to isn't garbage. |
| 31 | if not redirect_to or ' ' in redirect_to: |
| 32 | redirect_to = settings.LOGIN_REDIRECT_URL |
| 33 | |
| 34 | # Heavier security check -- redirects to http://example.com should |
| 35 | # not be allowed, but things like /view/?param=http://example.com |
| 36 | # should be allowed. This regex checks if there is a '//' *before* a |
| 37 | # question mark. |
| 38 | elif '//' in redirect_to and re.match(r'[^\?]*//', redirect_to): |
| 39 | redirect_to = settings.LOGIN_REDIRECT_URL |
| 40 | |
| 41 | # user already logged in |
| 42 | if request.user.is_authenticated(): |
| 43 | return HttpResponseRedirect(redirect_to) |
| 44 | |
33 | | # Light security check -- make sure redirect_to isn't garbage. |
34 | | if not redirect_to or ' ' in redirect_to: |
35 | | redirect_to = settings.LOGIN_REDIRECT_URL |
36 | | |
37 | | # Heavier security check -- redirects to http://example.com should |
38 | | # not be allowed, but things like /view/?param=http://example.com |
39 | | # should be allowed. This regex checks if there is a '//' *before* a |
40 | | # question mark. |
41 | | elif '//' in redirect_to and re.match(r'[^\?]*//', redirect_to): |
42 | | redirect_to = settings.LOGIN_REDIRECT_URL |
43 | | |
44 | | # Okay, security checks complete. Log the user in. |
| 48 | # Log the user in. |