Ticket #3011: #3011-extendable auth_user.diff

File #3011-extendable auth_user.diff, 3.5 KB (added by Kronuz, 4 years ago)
  • django/conf/global_settings.py

     
    379379# The number of days a password reset link is valid for
    380380PASSWORD_RESET_TIMEOUT_DAYS = 3
    381381
     382# The class to use as the default AUTH_USER for the authentication system.
     383AUTH_USER_MODULE = None
     384
    382385###########
    383386# TESTING #
    384387###########
  • django/contrib/auth/models.py

     
    11import datetime
    22import urllib
    33
     4from django.conf import settings
    45from django.contrib import auth
    56from django.core.exceptions import ImproperlyConfigured
    67from django.db import models
     
    198199    return False
    199200
    200201
    201 class User(models.Model):
     202class UserTemplate(models.Model):
    202203    """
    203204    Users within the Django authentication system are represented by this model.
    204205
     
    222223    class Meta:
    223224        verbose_name = _('user')
    224225        verbose_name_plural = _('users')
     226        abstract = True
    225227
    226228    def __unicode__(self):
    227229        return self.username
     
    287289                raise SiteProfileNotAvailable
    288290        return self._profile_cache
    289291
     292if settings.AUTH_USER_MODULE is not None:
     293    # Grab the AUTH_USER_MODULE path and classname from the settings.
     294    # auth_user_module_parts[0] = module path
     295    # auth_user_module_parts[1] = class name
     296    auth_user_module_parts = settings.AUTH_USER_MODULE.rsplit('.', 1)
     297    auth_user_module = __import__(auth_user_module_parts[0], {}, {}, [auth_user_module_parts[0]])
     298    # Store the auth_user model so it is accessible with the standard
     299    # 'from django.contrib.auth.models import User'
     300    User = getattr(auth_user_module, auth_user_module_parts[1])
     301
     302    # Add te User model to the django models cache
     303    # These two lines allow the custom auth_user model to play nicely with syncdb
     304    # and other systems that rely on functions like
     305    # django.db.models.loading.get_model(...)
     306    from django.db.models.loading import cache
     307    cache.register_models('auth', User)
     308
     309    # We need to remove whatever we used as the AUTH_USER_MODUlE from the
     310    # db cache so apps like contenttypes don't think that it's part
     311    # of contrib.auth
     312    del cache.app_models['auth'][User.__name__.lower()]
     313else:
     314    class User(UserTemplate):
     315        class Meta:
     316            verbose_name = _('user')
     317            verbose_name_plural = _('users')
     318
    290319class Message(models.Model):
    291320    """
    292321    The message system is a lightweight way to queue messages for given
  • django/contrib/admin/sites.py

     
    11import re
    22from django import http, template
    33from django.contrib.admin import ModelAdmin, actions
    4 from django.contrib.admin.forms import AdminAuthenticationForm
    54from django.contrib.auth import REDIRECT_FIELD_NAME
    65from django.contrib.contenttypes import views as contenttype_views
    76from django.views.decorators.csrf import csrf_protect
     
    315314        Displays the login form for the given HttpRequest.
    316315        """
    317316        from django.contrib.auth.views import login
     317        from django.contrib.admin.forms import AdminAuthenticationForm
    318318        context = {
    319319            'title': _('Log in'),
    320320            'root_path': self.root_path,
Back to Top