Ticket #148: PermitViewPublic.patch

File PermitViewPublic.patch, 11.5 KB (added by guest, 2 years ago)
  • PyLucid/index.py

    diff --git a/PyLucid/index.py b/PyLucid/index.py
    index a67a2b0..07c688b 100644
    a b  
    1919 
    2020import datetime, md5 
    2121 
    22 from django.http import HttpResponse, HttpResponsePermanentRedirect 
     22from django.http import HttpResponse, HttpResponsePermanentRedirect, HttpResponseRedirect 
    2323from django.template import RequestContext 
    2424from django.core.cache import cache 
    2525from django.core.exceptions import ImproperlyConfigured 
     
    3131 
    3232from PyLucid.system import plugin_manager 
    3333from PyLucid.system.response import SimpleStringIO 
    34 from PyLucid.system.exceptions import AccessDeny 
     34from PyLucid.system.exceptions import AccessDenied 
    3535from PyLucid.system.page_msg import PageMessages 
    3636from PyLucid.system.detect_page import get_current_page_obj, \ 
    3737                                                            get_default_page_id 
     
    209209    setup_debug(request) 
    210210 
    211211    # 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) 
    215219 
    216220    if use_cache: 
    217221        # It's a anonymous user -> Cache the cms page. 
     
    267271        output = plugin_manager.handle_command( 
    268272            context, local_response, module_name, method_name, url_args 
    269273        ) 
    270     except AccessDeny: 
    271         page_content = "[Permission Deny!]" 
     274    except AccessDenied: 
     275        page_content = "[Permission Denied!]" 
    272276    else: 
    273277        if output == None: 
    274278            # Plugin/Module has retuned the locale StringIO response object 
     
    323327    """ 
    324328    current_page_obj = _get_page(request, page_id) 
    325329    url = current_page_obj.get_absolute_url() 
    326     return redirect(request, url) 
    327  No newline at end of file 
     330    return redirect(request, url) 
  • PyLucid/plugins_internal/auth/auth.py

    diff --git a/PyLucid/plugins_internal/auth/auth.py b/PyLucid/plugins_internal/auth/auth.py
    index 1ab0717..04172e9 100644
    a b  
    11#!/usr/bin/python 
    2 # -*- coding: UTF-8 -*- 
     2# -*- coding: utf-8 -*- 
    33 
    44""" 
    55    PyLucid JS-SHA-Login 
     
    2626 
    2727import datetime 
    2828 
     29from django.http import HttpResponseRedirect 
    2930from django.core import mail 
    3031from django import newforms as forms 
    3132from django.contrib.auth.models import User 
     
    148149            ) 
    149150 
    150151        UsernameForm = forms.form_for_model(User, fields=("username",)) 
     152         
     153        next_url = self.request.GET.get('next',self.URLs['scriptRoot']) 
    151154 
    152155        def get_data(form): 
    153156            if DEBUG: self.page_msg(self.request.POST) 
     
    191194                else: 
    192195                    self.page_msg.red("Wrong POST data.") 
    193196 
     197        if DEBUG: self.page_msg("Next URL: %s" % next_url) 
    194198 
    195199        context = { 
    196200            "fallback_url": self.URLs.adminLink(""), 
    197201            "form": username_form, 
     202            "next_url": next_url, 
    198203        } 
    199204        self._render_template("input_username", context)#, debug=True) 
    200205 
     
    209214 
    210215        PasswordForm = forms.form_for_model(User, fields=("password",)) 
    211216 
     217        next_url = self.request.POST.get('next_url',self.URLs['scriptRoot']) 
     218 
    212219        # Change the default TextInput to a PasswordInput 
    213220        PasswordForm.base_fields['password'].widget = forms.PasswordInput() 
    214221 
    215222        context = { 
    216223            "username": user.username, 
    217224            "logout_url": self.URLs.methodLink("logout"), 
     225            "next_url": next_url, 
    218226        } 
    219227 
    220228        # Delete the default django help text: 
     
    231239                    self._insert_reset_link(context) 
    232240                else: 
    233241                    # Login ok 
    234                     return 
     242                    return HttpResponseRedirect(next_url) 
    235243 
    236244        context["form"] = password_form 
    237245        self._render_template("plaintext_login", context)#, debug=True) 
     
    260268        # rebuild the login/logout link: 
    261269        add_dynamic_context(self.request, self.context) 
    262270 
     271        next_url = self.request.POST.get('next_url',self.URLs['scriptRoot']) 
     272 
     273        # Redirect to next URL 
     274        HttpResponseRedirect(next_url) 
     275 
    263276 
    264277    def _sha_login(self, user): 
    265278        """ 
     
    275288                msg += " %s" % e 
    276289            self.pass_reset(user.username, msg) # Display the pass reset form 
    277290            return 
    278  
     291        next_url = self.request.POST.get('next_url',self.URLs['scriptRoot']) 
    279292        salt = js_login_data.salt 
    280293        context = { 
    281294            "username": user.username, 
    282295            "fallback_url": self.URLs.adminLink(""), 
    283296            "salt": salt, 
     297            "next_url": next_url, 
    284298            "PyLucid_media_url": settings.PYLUCID_MEDIA_URL, 
    285299        } 
    286300 
     
    326340                else: 
    327341                    if user: 
    328342                        self._login_user(user) 
    329                         return 
     343                        return HttpResponseRedirect(next_url) 
    330344                self._insert_reset_link(context) 
    331345                self.page_msg.red(msg) 
    332346 
     
    349363                password = password_form.cleaned_data["password"] 
    350364                self.page_msg("password:", password) 
    351365                self.page_msg("SHA-1 - Not implemented completly, yet :(") 
    352                 return 
     366                return HttpResponseRedirect(next_url) 
    353367        else: 
    354368            password_form = PasswordForm() 
    355369 
     
    372386        add_dynamic_context(self.request, self.context) 
    373387 
    374388        self.page_msg.green("You logged out.") 
     389        return HttpResponseRedirect(self.URLs['scriptRoot']) 
    375390 
    376391    #__________________________________________________________________________ 
    377392    # Password reset 
  • PyLucid/plugins_internal/auth/internal_pages/input_password.html

    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  
    55<form method="post" action="" name="login" onsubmit="check();"> 
    66  <input type="hidden" name="username" value="{{ username }}" /> 
    77  <input type="hidden" name="sha_login" value="little secure sha login" /> 
     8  <input type="hidden" name="next_url" value="{{ next_url }}" /> 
    89 
    910  <label for="plaintext_pass">{% trans 'Password' %}:</label> 
    1011  <input id="plaintext_pass" type="password" maxlength="128" /> 
     
    3435    submit_url = '.'; 
    3536    focus_id = 'plaintext_pass'; 
    3637    init(); 
    37 </script> 
    38  No newline at end of file 
     38</script> 
  • PyLucid/plugins_internal/auth/internal_pages/input_username.html

    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  
    1111  {% trans 'Log in' %}: 
    1212  <input type="submit" id="sha_button" name="sha_login" value="SHA-1 login" /> 
    1313  <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 }}" /> 
    1415</form> 
    1516</fieldset> 
    1617 
    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> 
  • PyLucid/plugins_internal/auth/internal_pages/plaintext_login.html

    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  
    33<form method="post" action="."> 
    44  <input type="hidden" name="username" value="{{ username }}" /> 
    55  <input type="hidden" name="plaintext_login" value="unsecure plaintext login" /> 
     6  <input type="hidden" name="next_url" value="{{ next_url }}" /> 
    67  {{ form }} 
    78  <input type="submit" value="{% trans 'Log in' %}" /> 
    89</form> 
     
    1112{% endif %} 
    1213</fieldset> 
    1314 
    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> 
  • PyLucid/system/detect_page.py

    diff --git a/PyLucid/system/detect_page.py b/PyLucid/system/detect_page.py
    index 7e75a14..7b81216 100755
    a b  
    1717""" 
    1818 
    1919from PyLucid.models import Page, Preference, Template 
     20from PyLucid.system.exceptions import AccessDenied 
    2021 
    2122from django.utils.translation import ugettext as _ 
    2223from django.core.exceptions import ImproperlyConfigured 
     
    8384 
    8485    shortcuts.reverse() 
    8586    wrong_shutcuts = [] 
     87    user = request.user 
    8688    for shortcut in shortcuts: 
    8789        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 
    8995        except Page.DoesNotExist: 
    9096            raise Http404(_("Page '%s' doesn't exists.") % shortcut) 
  • PyLucid/system/exceptions.py

    diff --git a/PyLucid/system/exceptions.py b/PyLucid/system/exceptions.py
    index f3238c1..f95f29b 100755
    a b  
    11#!/usr/bin/python 
    2 # -*- coding: UTF-8 -*- 
     2# -*- coding: utf-8 -*- 
    33 
    44""" 
    55    PyLucid own Exception's 
     
    88http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html 
    99""" 
    1010 
    11 class AccessDeny(Exception): 
     11class AccessDenied(Exception): 
    1212    pass 
    1313 
    1414class PluginError(Exception): 
     
    1616    For every error in a Plugin how should be displayed into the cms page. 
    1717    TODO: Catch this error in the plugin manager! 
    1818    """ 
    19     pass 
    20  No newline at end of file 
     19    pass 
  • PyLucid/system/plugin_manager.py

    diff --git a/PyLucid/system/plugin_manager.py b/PyLucid/system/plugin_manager.py
    index 4424beb..e955a81 100644
    a b  
    141141                # e.g. admin_menu 
    142142                return "" 
    143143            else: 
    144                 raise AccessDeny 
     144                raise AccessDenied 
    145145 
    146146    if method_cfg["must_admin"]: 
    147147        # The User must be an admin to use this method 
    148148        if not (request.user.is_superuser or request.user.is_staff): 
    149             raise AccessDeny 
     149            raise AccessDenied 
    150150 
    151151    URLs = context["URLs"] 
    152152    URLs.current_plugin = plugin_name