# Path: varnish_bans_manager/core/models/user.py
# class User(AbstractBaseUser, PermissionsMixin):
#     first_name = models.CharField(_('first name'), max_length=30, blank=True)
#     last_name = models.CharField(_('last name'), max_length=30, blank=True)
#     email = models.EmailField(_('email address'), unique=True)
#     is_staff = models.BooleanField(_('staff status'), default=False)
#     is_active = models.BooleanField(_('active'), default=True)
#     date_joined = models.DateTimeField(_('date joined'), default=timezone.now)
# 
#     objects = UserManager()
# 
#     USERNAME_FIELD = 'email'
#     REQUIRED_FIELDS = []
# 
#     def get_full_name(self):
#         if self.first_name or self.last_name:
#             return ', '.join([self.last_name, self.first_name])
#         else:
#             return self.email
# 
#     def get_short_name(self):
#         return self.first_name if self.first_name else self.email
# 
#     human_name = property(get_full_name)
# 
#     def editable_user_permission_labels(self):
#         permissions = filter(
#             lambda permission: permission.codename in PERMISSIONS,
#             self.user_permissions.all())
#         return [PERMISSIONS[permission.codename] for permission in permissions]
# 
#     class Meta:
#         permissions = (
#             ('can_access_advanced_ban_submission',
#              'Access advanced ban submission form'),
#             ('can_access_expert_ban_submission',
#              'Access expert ban submission form'),
#             ('can_access_bans_submissions',
#              'Access bans submissions'),
#             ('can_access_bans_status',
#              'Access bans status'),
#             ('can_access_caches_management',
#              'Access caches management'),
#             ('can_access_users_management',
#              'Access users management'),
#             ('can_access_settings',
#              'Access settings'),
#         )
#         verbose_name = _('user')
#         verbose_name_plural = _('users')
# 
# Path: varnish_bans_manager/core/models/user_profile.py
# class UserProfile(Model):
#     user = models.OneToOneField(
#         User,
#         related_name='profile',
#         null=False
#     )
#     creator = models.ForeignKey(
#         User,
#         related_name='+',
#         null=True,
#         on_delete=models.SET_NULL
#     )
#     photo = ImageField(
#         _('Photo'),
#         help_text=_(
#             'Upload a photo. It will only be visible by administrators.'),
#         upload_to=_photo_upload_destination,
#         null=True,
#         blank=True,
#         private=True,
#         attachment=False,
#         max_upload_size=1024 * 1024,
#         content_types=['image/jpeg', 'image/png'],
#         max_width=128,
#         max_height=128
#     )
#     revision = RevisionField()


from django import forms
from django.core.urlresolvers import reverse
from django.conf import settings
from django.utils.translation import ugettext_lazy as _
from django.utils.http import int_to_base36
from django.contrib.auth import authenticate
from django.contrib.auth.hashers import UNUSABLE_PASSWORD_PREFIX
from templated_email import send_templated_mail
from django.contrib.auth.tokens import default_token_generator
from varnish_bans_manager.core.models import User, UserProfile
        widget=forms.TextInput(attrs={'placeholder': _('e-mail address')}),
        max_length=64)

    error_messages = {
        'unknown': _(
            "That e-mail address doesn't have an associated "
            "user account. Are you sure you've registered?"),
        'unusable': _(
            'The user account associated with this e-mail '
            'address cannot reset the password.'),
    }

    def __init__(self, *args, **kwargs):
        super(PasswordResetForm, self).__init__(*args, **kwargs)
        self.user = None

    def clean_email(self):
        '''
        Validates that an active user exists with the given email address.

        '''
        email = self.cleaned_data.get('email')
        try:
            self.user = User.objects.filter(
                email__iexact=email,
                is_active=True).order_by('date_joined')[:1].get()
            if self.user.password.startswith(UNUSABLE_PASSWORD_PREFIX):
                raise forms.ValidationError(self.error_messages['unusable'])
            else:
                return email

# Path: varnish_bans_manager/core/models/user.py
# class User(AbstractBaseUser, PermissionsMixin):
#     first_name = models.CharField(_('first name'), max_length=30, blank=True)
#     last_name = models.CharField(_('last name'), max_length=30, blank=True)
#     email = models.EmailField(_('email address'), unique=True)
#     is_staff = models.BooleanField(_('staff status'), default=False)
#     is_active = models.BooleanField(_('active'), default=True)
#     date_joined = models.DateTimeField(_('date joined'), default=timezone.now)
# 
#     objects = UserManager()
# 
#     USERNAME_FIELD = 'email'
#     REQUIRED_FIELDS = []
# 
#     def get_full_name(self):
#         if self.first_name or self.last_name:
#             return ', '.join([self.last_name, self.first_name])
#         else:
#             return self.email
# 
#     def get_short_name(self):
#         return self.first_name if self.first_name else self.email
# 
#     human_name = property(get_full_name)
# 
#     def editable_user_permission_labels(self):
#         permissions = filter(
#             lambda permission: permission.codename in PERMISSIONS,
#             self.user_permissions.all())
#         return [PERMISSIONS[permission.codename] for permission in permissions]
# 
#     class Meta:
#         permissions = (
#             ('can_access_advanced_ban_submission',
#              'Access advanced ban submission form'),
#             ('can_access_expert_ban_submission',
#              'Access expert ban submission form'),
#             ('can_access_bans_submissions',
#              'Access bans submissions'),
#             ('can_access_bans_status',
#              'Access bans status'),
#             ('can_access_caches_management',
#              'Access caches management'),
#             ('can_access_users_management',
#              'Access users management'),
#             ('can_access_settings',
#              'Access settings'),
#         )
#         verbose_name = _('user')
#         verbose_name_plural = _('users')
# 
# Path: varnish_bans_manager/core/models/user_profile.py
# class UserProfile(Model):
#     user = models.OneToOneField(
#         User,
#         related_name='profile',
#         null=False
#     )
#     creator = models.ForeignKey(
#         User,
#         related_name='+',
#         null=True,
#         on_delete=models.SET_NULL
#     )
#     photo = ImageField(
#         _('Photo'),
#         help_text=_(
#             'Upload a photo. It will only be visible by administrators.'),
#         upload_to=_photo_upload_destination,
#         null=True,
#         blank=True,
#         private=True,
#         attachment=False,
#         max_upload_size=1024 * 1024,
#         content_types=['image/jpeg', 'image/png'],
#         max_width=128,
#         max_height=128
#     )
#     revision = RevisionField()


# Path: varnish_bans_manager/core/forms/user.py
from django import forms
from django.core.urlresolvers import reverse
from django.conf import settings
from django.utils.translation import ugettext_lazy as _
from django.utils.http import int_to_base36
from django.contrib.auth import authenticate
from django.contrib.auth.hashers import UNUSABLE_PASSWORD_PREFIX
from templated_email import send_templated_mail
from django.contrib.auth.tokens import default_token_generator
from varnish_bans_manager.core.models import User, UserProfile

        widget=forms.TextInput(attrs={'placeholder': _('e-mail address')}),
        max_length=64)

    error_messages = {
        'unknown': _(
            "That e-mail address doesn't have an associated "
            "user account. Are you sure you've registered?"),
        'unusable': _(
            'The user account associated with this e-mail '
            'address cannot reset the password.'),
    }

    def __init__(self, *args, **kwargs):
        super(PasswordResetForm, self).__init__(*args, **kwargs)
        self.user = None

    def clean_email(self):
        '''
        Validates that an active user exists with the given email address.

        '''
        email = self.cleaned_data.get('email')
        try:
            self.user = User.objects.filter(
                email__iexact=email,
                is_active=True).order_by('date_joined')[:1].get()
            if self.user.password.startswith(UNUSABLE_PASSWORD_PREFIX):
                raise forms.ValidationError(self.error_messages['unusable'])
            else:
                return email

        except User.DoesNotExist: