From d43d498ba2188df1083f301bfe0380fa88bc4ed9 Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Fri, 10 Feb 2006 21:35:29 +0000 Subject: [PATCH] magic-removal: Merged to [2300] git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@2301 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- AUTHORS | 1 + django/contrib/sessions/middleware.py | 6 ++++++ django/core/validators.py | 2 +- docs/authentication.txt | 15 +++++++++++++++ docs/sessions.txt | 6 ++++++ 5 files changed, 29 insertions(+), 1 deletion(-) diff --git a/AUTHORS b/AUTHORS index 44cee256a7..2296b3fc4f 100644 --- a/AUTHORS +++ b/AUTHORS @@ -36,6 +36,7 @@ answer newbie questions, and generally made Django that much better: David Ascher Arthur Jiri Barton + Ned Batchelder James Bennett Paul Bissex Simon Blanchard diff --git a/django/contrib/sessions/middleware.py b/django/contrib/sessions/middleware.py index 18f26de3e7..dae8a11554 100644 --- a/django/contrib/sessions/middleware.py +++ b/django/contrib/sessions/middleware.py @@ -25,6 +25,12 @@ class SessionWrapper(object): del self._session[key] self.modified = True + def keys(self): + return self._session.keys() + + def items(self): + return self._session.items() + def get(self, key, default=None): return self._session.get(key, default) diff --git a/django/core/validators.py b/django/core/validators.py index ce90f9dfe2..377b55fb4f 100644 --- a/django/core/validators.py +++ b/django/core/validators.py @@ -26,7 +26,7 @@ integer_re = re.compile(r'^-?\d+$') ip4_re = re.compile(r'^(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}$') phone_re = re.compile(r'^[A-PR-Y0-9]{3}-[A-PR-Y0-9]{3}-[A-PR-Y0-9]{4}$', re.IGNORECASE) slug_re = re.compile(r'^[-\w]+$') -url_re = re.compile(r'^http://\S+$') +url_re = re.compile(r'^https?://\S+$') lazy_inter = lazy(lambda a,b: str(a) % b, str) diff --git a/docs/authentication.txt b/docs/authentication.txt index 7780d668a5..81d1a4f52c 100644 --- a/docs/authentication.txt +++ b/docs/authentication.txt @@ -228,6 +228,21 @@ information. .. _request objects: http://www.djangoproject.com/documentation/request_response/#httprequest-objects .. _session documentation: http://www.djangoproject.com/documentation/sessions/ +How to log a user in +-------------------- + +To log a user in, do the following within a view:: + + from django.models.auth import users + request.session[users.SESSION_KEY] = some_user.id + +Because this uses sessions, you'll need to make sure you have +``SessionMiddleware`` enabled. See the `session documentation`_ for more +information. + +This assumes ``some_user`` is your ``User`` instance. Depending on your task, +you'll probably want to make sure to validate the user's username and password. + Limiting access to logged-in users ---------------------------------- diff --git a/docs/sessions.txt b/docs/sessions.txt index 30e4b9706e..be2ad1347c 100644 --- a/docs/sessions.txt +++ b/docs/sessions.txt @@ -45,6 +45,12 @@ It implements the following standard dictionary methods: * ``get(key, default=None)`` Example: ``fav_color = request.session.get('fav_color', 'red')`` + * ``keys()`` + **New in Django development version.** + + * ``items()`` + **New in Django development version.** + It also has these three methods: * ``set_test_cookie()``