Login

Tag "user"

Snippet List

Django substitution user

django-substitution-user is a project that makes it possible to substitute user, if you logged in as superuser https://github.com/torchingloom/django-substitution-user

  • django
  • user
Read More
Author: TA
  • 0
  • 0

User activation codes without additional database tables or fields

UserAuthCode generates an authentication code for Django user objects. This code can be used to verify the user's email address and to activate his account. Unlike other solutions there's no need add any tables or fields to your database. Current version is hosted on [GitHub](https://github.com/badzong/django-userauthcode). There's also an example how to use it in your Django project.

  • user
  • account
  • activation
Read More

Django Sudo

Staff can log in as a user, from a url to help with customer support or debugging.

  • admin
  • user
  • login
  • staff
  • sudo
Read More

staff_or_404 Decorator

Sometimes I don't want to reveal a staff-only view so I created this decorator, using ``django.contrib.admin.views.decorators.staff_member_required`` as my boilerplate. Non staff members are kicked to the 404 curb. Suggestion: Create a file, ``decorators.py`` in your project (or single app) and import like so: ``from myproject.app_name.decorators import staff_or_404``.

  • user
  • auth
  • decorators
  • staff
Read More

Support for permissions for anonymous users in django ModelBackend

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.

  • user
  • auth
  • permissions
  • anonymous
Read More
Author: jb
  • 1
  • 1

User groups template tag

This snippet is an improved version of the [ifusergroup](http://djangosnippets.org/snippets/1576/) tag that allows spaces in any of the group names. It also fixes a small bug where if a group didn't exist none of the subsequent groups would be checked.

  • tag
  • templatetag
  • user
  • auth
  • group
  • permissions
  • access-control
Read More

Password Validation - Require Letters and Numbers - no regex

Simple password validation for user registration - requires that password be 7 or more characters and contain both letters and numbers. Original validation with regex approach developed by kurtis. Optimized no-regex version based on code from watchedman ran as fast or significantly faster on all systems on which we tested it.

  • registration
  • model
  • regex
  • user
  • validation
  • form
  • password
Read More

Multiple User subclasses custom Auth backend

A project I'm working on requires multiple different classes of users, all with different fields/attributes. Having a single UserProfile class with a generic relation was a complete pain in practice. So, I changed my classes to all subclass User directly and then used django-model-utils to create a custom ModelBackend that returns the appropriate class when accessing request.user. The InheritanceQuerySet manager provided by django-model-utils makes it all possible and with only a single database query. No need to add anything directly to the User class, by the way. Just subclass it directly with each of your custom classes: class CustomUser1(User): field1 = models.CharField(...) class CustomUser2(User): field2 = models.CharField(...)

  • user
  • profile
  • auth
  • subclass
  • backend
  • modelbackend
Read More

User Profile minimal code

Usually I start an authentication app with this model. Don't forget to set it up in the settings file AUTH_PROFILE_MODULE = 'authentication.UserProfile'

  • user
  • profile
  • signals
  • get_profile
Read More

restrict user access to modeladmin via metaclass

* Include `__metaclass__ = user_lock` to your ModelAdmin class * Add `__target__ = path_to_user_field` somewhere in the ModelAdmin * done! `__target__` is what will be used in the `filter` call. examples `'user'` or `'author'` or `'message__user'` e.t.c. The result of `__target__` is the field that is then checked against `request.user`

  • admin
  • user
  • restrict
  • model-admin
Read More

Get current user without a request object

Mechanism to obtain a `request.user` object without the `request` object itself. Requires `LocalUserMiddleware` in `MIDDLEWARE_CLASSES` settings variable. **Important**: works under assumption that within a web server each request is handled by a separate thread (as for example in the Apache HTTP server). **Beware**: [security threat](http://code.djangoproject.com/wiki/CookBookThreadlocalsAndUser), although ["thread locals only appears to be a security threat if a system has already been seriously compromised, at which point there'd be easier attacks to execute"](http://groups.google.com/group/django-users/browse_thread/thread/e7af359d7d183e04). **Dev note**: works fine with one-threaded Django's development server, each request resets current user; no worries 'bout many media requests - they won't (at least shouldn't) be using Django on the production server. **Ref**: originally found in the gatekeeper app.

  • middleware
  • user
  • request
  • local thread
Read More

adding fields to User model

This code adds new field to Django user model. It must be executed early as much as possible, so put this code to __init__.py of some application.

  • fields
  • model
  • user
  • auth
  • field
Read More

Combine ProfileForm an UserForm in one.

Using this method you can combine form for standart django.contrib.auth.models.User model and for your project profile model. As now, ProfileForm can be used as usual, and it will also contain UserForm fields.

  • forms
  • user
  • profile
Read More

44 snippets posted so far.