from django.conf.urls import patterns, include, url
from django.views.generic import TemplateView
from store.forms import CustomRegistrationFormUniqueEmail
from registration.backends.default.views import RegistrationView
urlpatterns = patterns('',
url(r'^$',
TemplateView.as_view(template_name='index.html'),
name='index'),
url(r'^registration/$',
RegistrationView.as_view(form_class=CustomRegistrationFormUniqueEmail),
name='re-gistration_register'),
url(r'^accounts/',
include('registration.backends.simple.urls')),
url(r'^accounts/profile/',
TemplateView.as_view(template_name='profile.html'),
name='profile'),
url(r'^login/',
'django.contrib.auth.views.login',
name='login')
)
from django import forms
from registration.forms import RegistrationFormUniqueEmail
class CustomRegistrationFormUniqueEmail(RegistrationFormUniqueEmail):
new_field = forms.CharField(label='Your name', max_length=100)
from django.db import models
from django.contrib.auth.models import User as AbstractBaseUser, UserManager as BaseUserManager
# Create your models here.
class CustomUser(AbstractBaseUser):
new_field = models.CharField(max_length=25)
objects = BaseUserManager()
USERNAME_FIELD = 'new_field'
class User(AbstractBaseUser):
# менеджер модели по умолчанию
objects = UserManager()
class Meta:
verbose_name = _('user.model.verbose_name')
verbose_name_plural = _('user.model.verbose_name_plural')
# переопределяем поле username
USERNAME_FIELD = 'email'
# емаил = логин
email = models.EmailField(_('user.model.email'), max_length=100, unique=True)
# имя
firstname = models.CharField(_('user.model.firstname'), blank=True, max_length=50)
# фамилия
lastname = models.CharField(_('user.model.lastname'), blank=True, max_length=50)
# блокировка пользователя
is_disabled = models.BooleanField(_('user.model.is_disabled'), default=False)
# доступ к админке
is_admin = models.BooleanField(_('user.model.is_admin'), default=False)
# супер пользователь
is_superuser = models.BooleanField(_('user.model.is_superuser'), default=False)
def get_full_name(self):
return '%s %s' % (self.lastname, self.firstname)
def get_short_name(self):
return self.firstname
def __str__(self):
return str(self.email)
def has_perm(self, perm, obj=None):
return True
def has_module_perms(self, app_label):
return True
@property
def is_staff(self):
return self.is_admin
@property
def is_superuser(self):
return self.is_admin
from django.contrib.auth.models import BaseUserManager
class UserManager(BaseUserManager):
def create_user(self, email, password=None):
"""
Creates and saves a User with the given email and password.
"""
if not email:
raise ValueError('Users must have an email address')
user = self.model(email=self.normalize_email(email), )
user.set_password(password)
user.save(using=self._db)
return user
def create_superuser(self, email, password):
"""
Creates and saves a superuser with the given email and password.
"""
user = self.create_user(email, password=password)
user.is_admin = True
user.save(using=self._db)
return user
# модель для персоны
AUTH_USER_MODEL = 'user.User'