anonymous_required decorator
Decorator to preserve view from logged users.
- decorator
- auth
- anonymous
Decorator to preserve view from logged users.
Model backend that enables permissions for AnonymusUsers. I wanted it to be as simple as possible so anonymous users just forward their permission checks to some fixed user model. This instance can be edited via django admin, assigned to groups, etc. To control which user will represent anonymous user you use ANONYMOUS_USER_NAME setting in settings file. To provide some sensible level of security i enforce following for user that represents anonymous user: * This user must have password equal to UNUSABLE_PASSWORD * This user may not log in * You cant cange password for this user via admin. You need to enable this backend by setting AUTHENTICATION_BACKENDS. Please note that you should not place this backend alongside django ModelBackend. This backend inherits from it.
This is an addition to Django's cache_page decorator. I wanted to cache pages for anonymous users but not cache the same page for logged in users. There's middleware to do this at a site-wide level, and it also gives you the ability to partition anonymous users, but then you have to tell Django which pages not to cache with @never_cache.
Point '^accounts/login/$' or whatever your custom login path is to the 'negotiate_ntlm' view. This allows you to keep anonymous authentication enabled on IIS and easily lock down just the parts of the site you need to (e.g. [admin](http://djangosnippets.org/snippets/2127/)).
If you want anonymous visitors to your site, or parts of your site to be authenticated as real users so that you can treat them as such in your views and models, use this snippet. Add the above AuthenticationBackendAnonymous middleware into AUTHENTICATION_BACKENDS in your settings.py and use the snippet anonymous_or_real(request) in your views, which returns a user. Comment out the bit where it creates a profile if you are not using profiles.
5 snippets posted so far.