Changeset 1439
- Timestamp:
- 02/22/08 14:57:37 (2 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/pylucid/PyLucid/plugins_internal/auth/auth.py
r1416 r1439 6 6 ~~~~~~~~~~~~~~~~~~~~ 7 7 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? 13 30 http://www.djangoproject.com/documentation/sessions/#clearing-the-session-table 14 31 15 32 Last commit info: 16 ~~~~~~~~~ 33 ~~~~~~~~~~~~~~~~~ 17 34 LastChangedDate: $LastChangedDate$ 18 35 Revision.......: $Rev$ … … 50 67 from PyLucid.system.BasePlugin import PyLucidBasePlugin 51 68 from PyLucid.system.context_processors import add_dynamic_context 52 from PyLucid.models import JS_LoginData 69 from PyLucid.models import JS_LoginData, Preference 70 from PyLucid.system.detect_page import get_default_page 53 71 54 72 … … 150 168 151 169 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", "") 154 172 155 173 def get_data(form): … … 215 233 PasswordForm = forms.form_for_model(User, fields=("password",)) 216 234 217 next_url = self.request.POST.get('next_url', self.URLs['scriptRoot'])235 next_url = self.request.POST.get('next_url', "") 218 236 219 237 # Change the default TextInput to a PasswordInput … … 228 246 # Delete the default django help text: 229 247 PasswordForm.base_fields['password'].help_text = "" 230 password_form = PasswordForm(self.request.POST)231 248 232 249 if "password" in self.request.POST: 250 password_form = PasswordForm(self.request.POST) 233 251 if password_form.is_valid(): 234 252 password = password_form.cleaned_data["password"] 235 253 try: 236 self._check_plaintext_password(password, user)254 return self._check_plaintext_password(password, user) 237 255 except WrongPassword, msg: 238 256 self.page_msg.red(msg) 239 257 self._insert_reset_link(context) 240 else: 241 # Login ok 242 return HttpResponseRedirect(next_url) 258 else: 259 password_form = PasswordForm() 243 260 244 261 context["form"] = password_form … … 255 272 raise WrongPassword("Wrong password.") 256 273 257 self._login_user(user)274 return self._login_user(user) 258 275 259 276 … … 262 279 Log the >user< in. 263 280 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). 264 283 """ 265 284 self.page_msg.green(_("Password ok.")) … … 269 288 add_dynamic_context(self.request, self.context) 270 289 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) 275 295 276 296 … … 340 360 else: 341 361 if user: 342 self._login_user(user)343 return HttpResponseRedirect(next_url) 362 return self._login_user(user) 363 344 364 self._insert_reset_link(context) 345 365 self.page_msg.red(msg) … … 356 376 357 377 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() 369 379 370 380 context["form"] = password_form … … 387 397 388 398 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) 390 406 391 407 #__________________________________________________________________________