Changeset 1439

Show
Ignore:
Timestamp:
02/22/08 14:57:37 (2 years ago)
Author:
JensDiemer
Message:

auth - change "next_url" behavior:
-On login: Redirect only, if "next_url" information exists. Otherwiese stay at the current page (ID in _command url).
-On logout: Ony redirect to the default page, if the current page not viewable for anonymous.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/pylucid/PyLucid/plugins_internal/auth/auth.py

    r1416 r1439  
    66    ~~~~~~~~~~~~~~~~~~~~ 
    77 
    8     A secure JavaScript SHA-1 Login. 
    9  
    10     TODO: Only plaintext login implemented!!! 
    11  
    12     TODO: Clearing the session table? 
     8    A secure JavaScript SHA-1 Login and a plaintext fallback login. 
     9 
     10    two steps 
     11    ~~~~~~~~~ 
     12    We split the login into two steps: 
     13        - step-1 -> input the username 
     14        - step-2 -> input the password 
     15 
     16    the "next_url" 
     17    ~~~~~~~~~~~~~~ 
     18    The "next_url" is for a redirect after a login. It's optional. 
     19    If there doesn't exist a "next_url" information, PyLucid displayed the 
     20    current page. In every _command URL is the current page ID. 
     21 
     22    The "next_url" is in the first step (input the username) a GET parameter. 
     23    e.g.: localhost/_command/1/auth/login/?next=/ExamplePages/not-viewable 
     24    Then, the "next_url" information went into the form and comes back in the 
     25    POST data. 
     26 
     27    TODO 
     28    ~~~~ 
     29    Clearing the session table? 
    1330    http://www.djangoproject.com/documentation/sessions/#clearing-the-session-table 
    1431 
    1532    Last commit info: 
    16     ~~~~~~~~~ 
     33    ~~~~~~~~~~~~~~~~~ 
    1734    LastChangedDate: $LastChangedDate$ 
    1835    Revision.......: $Rev$ 
     
    5067from PyLucid.system.BasePlugin import PyLucidBasePlugin 
    5168from PyLucid.system.context_processors import add_dynamic_context 
    52 from PyLucid.models import JS_LoginData 
     69from PyLucid.models import JS_LoginData, Preference 
     70from PyLucid.system.detect_page import get_default_page 
    5371 
    5472 
     
    150168 
    151169        UsernameForm = forms.form_for_model(User, fields=("username",)) 
    152          
    153         next_url = self.request.GET.get('next',self.URLs['scriptRoot']) 
     170 
     171        next_url = self.request.GET.get("next", "") 
    154172 
    155173        def get_data(form): 
     
    215233        PasswordForm = forms.form_for_model(User, fields=("password",)) 
    216234 
    217         next_url = self.request.POST.get('next_url',self.URLs['scriptRoot']) 
     235        next_url = self.request.POST.get('next_url', "") 
    218236 
    219237        # Change the default TextInput to a PasswordInput 
     
    228246        # Delete the default django help text: 
    229247        PasswordForm.base_fields['password'].help_text = "" 
    230         password_form = PasswordForm(self.request.POST) 
    231248 
    232249        if "password" in self.request.POST: 
     250            password_form = PasswordForm(self.request.POST) 
    233251            if password_form.is_valid(): 
    234252                password = password_form.cleaned_data["password"] 
    235253                try: 
    236                     self._check_plaintext_password(password, user) 
     254                    return self._check_plaintext_password(password, user) 
    237255                except WrongPassword, msg: 
    238256                    self.page_msg.red(msg) 
    239257                    self._insert_reset_link(context) 
    240                 else: 
    241                     # Login ok 
    242                     return HttpResponseRedirect(next_url) 
     258        else: 
     259            password_form = PasswordForm() 
    243260 
    244261        context["form"] = password_form 
     
    255272            raise WrongPassword("Wrong password.") 
    256273 
    257         self._login_user(user) 
     274        return self._login_user(user) 
    258275 
    259276 
     
    262279        Log the >user< in. 
    263280        Used in self._check_plaintext_password() and self._sha_login() 
     281        Returns a redirect, if "next_url" exists otherwise returns None (for 
     282        display the current page). 
    264283        """ 
    265284        self.page_msg.green(_("Password ok.")) 
     
    269288        add_dynamic_context(self.request, self.context) 
    270289 
    271         next_url = self.request.POST.get('next_url',self.URLs['scriptRoot']) 
    272  
    273         # Redirect to next URL 
    274         HttpResponseRedirect(next_url) 
     290        if self.request.POST.get("next_url","") != "": 
     291            next_url = self.request.POST['next_url'] 
     292 
     293            # Redirect to next URL 
     294            return HttpResponseRedirect(next_url) 
    275295 
    276296 
     
    340360                else: 
    341361                    if user: 
    342                         self._login_user(user) 
    343                         return HttpResponseRedirect(next_url) 
     362                        return self._login_user(user) 
     363 
    344364                self._insert_reset_link(context) 
    345365                self.page_msg.red(msg) 
     
    356376 
    357377        PasswordForm = forms.form_for_model(User, fields=("password",)) 
    358  
    359         if self.request.method == 'POST': 
    360             if DEBUG: self.page_msg(self.request.POST) 
    361             password_form = PasswordForm(self.request.POST) 
    362             if password_form.is_valid(): 
    363                 password = password_form.cleaned_data["password"] 
    364                 self.page_msg("password:", password) 
    365                 self.page_msg("SHA-1 - Not implemented completly, yet :(") 
    366                 return HttpResponseRedirect(next_url) 
    367         else: 
    368             password_form = PasswordForm() 
     378        password_form = PasswordForm() 
    369379 
    370380        context["form"] = password_form 
     
    387397 
    388398        self.page_msg.green("You logged out.") 
    389         return HttpResponseRedirect(self.URLs['scriptRoot']) 
     399 
     400        if not self.current_page.permitViewPublic: 
     401            # The current page, can't see anonymous users -> reriect to the 
     402            # default page 
     403            default_page = get_default_page(self.request) 
     404            url = default_page.get_absolute_url() 
     405            return HttpResponseRedirect(url) 
    390406 
    391407    #__________________________________________________________________________