diff --git a/PyLucid/index.py b/PyLucid/index.py
index a67a2b0..07c688b 100644
|
a
|
b
|
|
| 19 | 19 | |
| 20 | 20 | import datetime, md5 |
| 21 | 21 | |
| 22 | | from django.http import HttpResponse, HttpResponsePermanentRedirect |
| | 22 | from django.http import HttpResponse, HttpResponsePermanentRedirect, HttpResponseRedirect |
| 23 | 23 | from django.template import RequestContext |
| 24 | 24 | from django.core.cache import cache |
| 25 | 25 | from django.core.exceptions import ImproperlyConfigured |
| … |
… |
|
| 31 | 31 | |
| 32 | 32 | from PyLucid.system import plugin_manager |
| 33 | 33 | from PyLucid.system.response import SimpleStringIO |
| 34 | | from PyLucid.system.exceptions import AccessDeny |
| | 34 | from PyLucid.system.exceptions import AccessDenied |
| 35 | 35 | from PyLucid.system.page_msg import PageMessages |
| 36 | 36 | from PyLucid.system.detect_page import get_current_page_obj, \ |
| 37 | 37 | get_default_page_id |
| … |
… |
|
| 209 | 209 | setup_debug(request) |
| 210 | 210 | |
| 211 | 211 | # Get the response for the requested cms page: |
| 212 | | current_page_obj = get_current_page_obj(request, url) |
| 213 | | context = _get_context(request, current_page_obj) |
| 214 | | response = _render_cms_page(context) |
| | 212 | try: |
| | 213 | current_page_obj = get_current_page_obj(request, url) |
| | 214 | context = _get_context(request, current_page_obj) |
| | 215 | response = _render_cms_page(context) |
| | 216 | except AccessDenied: |
| | 217 | path = '/'.join(('',settings.COMMAND_URL_PREFIX,'1','auth','login','?next=%s')) |
| | 218 | return HttpResponseRedirect(path % request.path) |
| 215 | 219 | |
| 216 | 220 | if use_cache: |
| 217 | 221 | # It's a anonymous user -> Cache the cms page. |
| … |
… |
|
| 267 | 271 | output = plugin_manager.handle_command( |
| 268 | 272 | context, local_response, module_name, method_name, url_args |
| 269 | 273 | ) |
| 270 | | except AccessDeny: |
| 271 | | page_content = "[Permission Deny!]" |
| | 274 | except AccessDenied: |
| | 275 | page_content = "[Permission Denied!]" |
| 272 | 276 | else: |
| 273 | 277 | if output == None: |
| 274 | 278 | # Plugin/Module has retuned the locale StringIO response object |
| … |
… |
|
| 323 | 327 | """ |
| 324 | 328 | current_page_obj = _get_page(request, page_id) |
| 325 | 329 | url = current_page_obj.get_absolute_url() |
| 326 | | return redirect(request, url) |
| 327 | | No newline at end of file |
| | 330 | return redirect(request, url) |
diff --git a/PyLucid/plugins_internal/auth/auth.py b/PyLucid/plugins_internal/auth/auth.py
index 1ab0717..04172e9 100644
|
a
|
b
|
|
| 1 | 1 | #!/usr/bin/python |
| 2 | | # -*- coding: UTF-8 -*- |
| | 2 | # -*- coding: utf-8 -*- |
| 3 | 3 | |
| 4 | 4 | """ |
| 5 | 5 | PyLucid JS-SHA-Login |
| … |
… |
|
| 26 | 26 | |
| 27 | 27 | import datetime |
| 28 | 28 | |
| | 29 | from django.http import HttpResponseRedirect |
| 29 | 30 | from django.core import mail |
| 30 | 31 | from django import newforms as forms |
| 31 | 32 | from django.contrib.auth.models import User |
| … |
… |
|
| 148 | 149 | ) |
| 149 | 150 | |
| 150 | 151 | UsernameForm = forms.form_for_model(User, fields=("username",)) |
| | 152 | |
| | 153 | next_url = self.request.GET.get('next',self.URLs['scriptRoot']) |
| 151 | 154 | |
| 152 | 155 | def get_data(form): |
| 153 | 156 | if DEBUG: self.page_msg(self.request.POST) |
| … |
… |
|
| 191 | 194 | else: |
| 192 | 195 | self.page_msg.red("Wrong POST data.") |
| 193 | 196 | |
| | 197 | if DEBUG: self.page_msg("Next URL: %s" % next_url) |
| 194 | 198 | |
| 195 | 199 | context = { |
| 196 | 200 | "fallback_url": self.URLs.adminLink(""), |
| 197 | 201 | "form": username_form, |
| | 202 | "next_url": next_url, |
| 198 | 203 | } |
| 199 | 204 | self._render_template("input_username", context)#, debug=True) |
| 200 | 205 | |
| … |
… |
|
| 209 | 214 | |
| 210 | 215 | PasswordForm = forms.form_for_model(User, fields=("password",)) |
| 211 | 216 | |
| | 217 | next_url = self.request.POST.get('next_url',self.URLs['scriptRoot']) |
| | 218 | |
| 212 | 219 | # Change the default TextInput to a PasswordInput |
| 213 | 220 | PasswordForm.base_fields['password'].widget = forms.PasswordInput() |
| 214 | 221 | |
| 215 | 222 | context = { |
| 216 | 223 | "username": user.username, |
| 217 | 224 | "logout_url": self.URLs.methodLink("logout"), |
| | 225 | "next_url": next_url, |
| 218 | 226 | } |
| 219 | 227 | |
| 220 | 228 | # Delete the default django help text: |
| … |
… |
|
| 231 | 239 | self._insert_reset_link(context) |
| 232 | 240 | else: |
| 233 | 241 | # Login ok |
| 234 | | return |
| | 242 | return HttpResponseRedirect(next_url) |
| 235 | 243 | |
| 236 | 244 | context["form"] = password_form |
| 237 | 245 | self._render_template("plaintext_login", context)#, debug=True) |
| … |
… |
|
| 260 | 268 | # rebuild the login/logout link: |
| 261 | 269 | add_dynamic_context(self.request, self.context) |
| 262 | 270 | |
| | 271 | next_url = self.request.POST.get('next_url',self.URLs['scriptRoot']) |
| | 272 | |
| | 273 | # Redirect to next URL |
| | 274 | HttpResponseRedirect(next_url) |
| | 275 | |
| 263 | 276 | |
| 264 | 277 | def _sha_login(self, user): |
| 265 | 278 | """ |
| … |
… |
|
| 275 | 288 | msg += " %s" % e |
| 276 | 289 | self.pass_reset(user.username, msg) # Display the pass reset form |
| 277 | 290 | return |
| 278 | | |
| | 291 | next_url = self.request.POST.get('next_url',self.URLs['scriptRoot']) |
| 279 | 292 | salt = js_login_data.salt |
| 280 | 293 | context = { |
| 281 | 294 | "username": user.username, |
| 282 | 295 | "fallback_url": self.URLs.adminLink(""), |
| 283 | 296 | "salt": salt, |
| | 297 | "next_url": next_url, |
| 284 | 298 | "PyLucid_media_url": settings.PYLUCID_MEDIA_URL, |
| 285 | 299 | } |
| 286 | 300 | |
| … |
… |
|
| 326 | 340 | else: |
| 327 | 341 | if user: |
| 328 | 342 | self._login_user(user) |
| 329 | | return |
| | 343 | return HttpResponseRedirect(next_url) |
| 330 | 344 | self._insert_reset_link(context) |
| 331 | 345 | self.page_msg.red(msg) |
| 332 | 346 | |
| … |
… |
|
| 349 | 363 | password = password_form.cleaned_data["password"] |
| 350 | 364 | self.page_msg("password:", password) |
| 351 | 365 | self.page_msg("SHA-1 - Not implemented completly, yet :(") |
| 352 | | return |
| | 366 | return HttpResponseRedirect(next_url) |
| 353 | 367 | else: |
| 354 | 368 | password_form = PasswordForm() |
| 355 | 369 | |
| … |
… |
|
| 372 | 386 | add_dynamic_context(self.request, self.context) |
| 373 | 387 | |
| 374 | 388 | self.page_msg.green("You logged out.") |
| | 389 | return HttpResponseRedirect(self.URLs['scriptRoot']) |
| 375 | 390 | |
| 376 | 391 | #__________________________________________________________________________ |
| 377 | 392 | # Password reset |
diff --git a/PyLucid/plugins_internal/auth/internal_pages/input_password.html b/PyLucid/plugins_internal/auth/internal_pages/input_password.html
index fd04294..c557fdd 100755
|
a
|
b
|
|
| 5 | 5 | <form method="post" action="" name="login" onsubmit="check();"> |
| 6 | 6 | <input type="hidden" name="username" value="{{ username }}" /> |
| 7 | 7 | <input type="hidden" name="sha_login" value="little secure sha login" /> |
| | 8 | <input type="hidden" name="next_url" value="{{ next_url }}" /> |
| 8 | 9 | |
| 9 | 10 | <label for="plaintext_pass">{% trans 'Password' %}:</label> |
| 10 | 11 | <input id="plaintext_pass" type="password" maxlength="128" /> |
| … |
… |
|
| 34 | 35 | submit_url = '.'; |
| 35 | 36 | focus_id = 'plaintext_pass'; |
| 36 | 37 | init(); |
| 37 | | </script> |
| 38 | | No newline at end of file |
| | 38 | </script> |
diff --git a/PyLucid/plugins_internal/auth/internal_pages/input_username.html b/PyLucid/plugins_internal/auth/internal_pages/input_username.html
index 68d104e..a94bdda 100644
|
a
|
b
|
|
| 11 | 11 | {% trans 'Log in' %}: |
| 12 | 12 | <input type="submit" id="sha_button" name="sha_login" value="SHA-1 login" /> |
| 13 | 13 | <input type="submit" id="plaintext_button" name="plaintext_login" value="unsecure plaintext login" onclick="return confirm('Do you realy want to send your password in plaintext?')"/> |
| | 14 | <input type="hidden" name="next_url" value="{{ next_url }}" /> |
| 14 | 15 | </form> |
| 15 | 16 | </fieldset> |
| 16 | 17 | |
| 17 | | <script type="text/javascript">document.getElementById("id_username").focus();</script> |
| 18 | | No newline at end of file |
| | 18 | <script type="text/javascript">document.getElementById("id_username").focus();</script> |
diff --git a/PyLucid/plugins_internal/auth/internal_pages/plaintext_login.html b/PyLucid/plugins_internal/auth/internal_pages/plaintext_login.html
index 0b85944..ef112d3 100755
|
a
|
b
|
|
| 3 | 3 | <form method="post" action="."> |
| 4 | 4 | <input type="hidden" name="username" value="{{ username }}" /> |
| 5 | 5 | <input type="hidden" name="plaintext_login" value="unsecure plaintext login" /> |
| | 6 | <input type="hidden" name="next_url" value="{{ next_url }}" /> |
| 6 | 7 | {{ form }} |
| 7 | 8 | <input type="submit" value="{% trans 'Log in' %}" /> |
| 8 | 9 | </form> |
| … |
… |
|
| 11 | 12 | {% endif %} |
| 12 | 13 | </fieldset> |
| 13 | 14 | |
| 14 | | <script type="text/javascript">document.getElementById("id_password").focus();</script> |
| 15 | | No newline at end of file |
| | 15 | <script type="text/javascript">document.getElementById("id_password").focus();</script> |
diff --git a/PyLucid/system/detect_page.py b/PyLucid/system/detect_page.py
index 7e75a14..7b81216 100755
|
a
|
b
|
|
| 17 | 17 | """ |
| 18 | 18 | |
| 19 | 19 | from PyLucid.models import Page, Preference, Template |
| | 20 | from PyLucid.system.exceptions import AccessDenied |
| 20 | 21 | |
| 21 | 22 | from django.utils.translation import ugettext as _ |
| 22 | 23 | from django.core.exceptions import ImproperlyConfigured |
| … |
… |
|
| 83 | 84 | |
| 84 | 85 | shortcuts.reverse() |
| 85 | 86 | wrong_shutcuts = [] |
| | 87 | user = request.user |
| 86 | 88 | for shortcut in shortcuts: |
| 87 | 89 | try: |
| 88 | | return Page.objects.get(shortcut__exact=shortcut) |
| | 90 | page = Page.objects.get(shortcut__exact=shortcut) |
| | 91 | if user.is_anonymous() and not page.permitViewPublic: |
| | 92 | raise AccessDenied |
| | 93 | else: |
| | 94 | return page |
| 89 | 95 | except Page.DoesNotExist: |
| 90 | 96 | raise Http404(_("Page '%s' doesn't exists.") % shortcut) |
diff --git a/PyLucid/system/exceptions.py b/PyLucid/system/exceptions.py
index f3238c1..f95f29b 100755
|
a
|
b
|
|
| 1 | 1 | #!/usr/bin/python |
| 2 | | # -*- coding: UTF-8 -*- |
| | 2 | # -*- coding: utf-8 -*- |
| 3 | 3 | |
| 4 | 4 | """ |
| 5 | 5 | PyLucid own Exception's |
| … |
… |
|
| 8 | 8 | http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html |
| 9 | 9 | """ |
| 10 | 10 | |
| 11 | | class AccessDeny(Exception): |
| | 11 | class AccessDenied(Exception): |
| 12 | 12 | pass |
| 13 | 13 | |
| 14 | 14 | class PluginError(Exception): |
| … |
… |
|
| 16 | 16 | For every error in a Plugin how should be displayed into the cms page. |
| 17 | 17 | TODO: Catch this error in the plugin manager! |
| 18 | 18 | """ |
| 19 | | pass |
| 20 | | No newline at end of file |
| | 19 | pass |
diff --git a/PyLucid/system/plugin_manager.py b/PyLucid/system/plugin_manager.py
index 4424beb..e955a81 100644
|
a
|
b
|
|
| 141 | 141 | # e.g. admin_menu |
| 142 | 142 | return "" |
| 143 | 143 | else: |
| 144 | | raise AccessDeny |
| | 144 | raise AccessDenied |
| 145 | 145 | |
| 146 | 146 | if method_cfg["must_admin"]: |
| 147 | 147 | # The User must be an admin to use this method |
| 148 | 148 | if not (request.user.is_superuser or request.user.is_staff): |
| 149 | | raise AccessDeny |
| | 149 | raise AccessDenied |
| 150 | 150 | |
| 151 | 151 | URLs = context["URLs"] |
| 152 | 152 | URLs.current_plugin = plugin_name |