# Path: diary/models.py
# class Customer(User):
#     """ Customer/Client/Patient details.
#     """
# 
#     # gender options
#     MALE = 'M'
#     FEMALE = 'F'
#     GENDER_CHOICES = (
#         (MALE, 'Male'),
#         (FEMALE, 'Female'),
#     )
# 
#     # title options
#     MR = 'MR'
#     MRS = 'MRS'
#     MISS = 'MISS'
#     MS = 'MS'
#     DR = 'DR'
#     PROF = 'PROF'
#     REV = 'REV'
#     TITLE_CHOICES = (
#         (MR, 'Mr'),
#         (MRS, 'Mrs'),
#         (MISS, 'Miss'),
#         (MS, 'Ms'),
#         (DR, 'Dr'),
#         (PROF, 'Prof'),
#         (REV, 'Rev'),
#     )
# 
# 
#     class Meta(User.Meta):
#         verbose_name = 'Customer'
#         verbose_name_plural = 'Customers'
# 
# 
#     objects = CustomerManager()
# 
#     title = models.CharField(
#         max_length=4,
#         choices=TITLE_CHOICES,
#         default=MRS,
#     )
#     phone = models.CharField(
#         max_length=20,
#         validators=[phoneValidator],
#         blank=True,
#         null=True)
#     date_of_birth = models.DateField(blank=True, null=True)
#     gender = models.CharField(
#         max_length=1,
#         choices=GENDER_CHOICES,
#         default=FEMALE,
#     )
#     notes = models.TextField(blank=True)
# 
# 
#     def natural_key(self):
#         """
#         Serialisation aid. Not needed ATM.
#         """
#         return (self.username,)
# 
# 
#     def age(self):
#         """
#         Age to the nearest year.
#         """
#         if self.date_of_birth:
#             now = timezone.now()
#             return now.year - self.date_of_birth.year
#         return None
# 
# 
#     def __str__(self):
#         return '{0} {1}'.format(self.first_name, self.last_name)


from django.contrib.auth.backends import ModelBackend
from django.contrib.auth.models import User
from .models import Customer


class CustomerAuthBackend(ModelBackend):
    """
    Home-spun backend in response to django-model-utils functionality not
    working for Django >~ 2
    """
    def get_user(self, user_id):
        try:

# Path: diary/models.py
# class Customer(User):
#     """ Customer/Client/Patient details.
#     """
# 
#     # gender options
#     MALE = 'M'
#     FEMALE = 'F'
#     GENDER_CHOICES = (
#         (MALE, 'Male'),
#         (FEMALE, 'Female'),
#     )
# 
#     # title options
#     MR = 'MR'
#     MRS = 'MRS'
#     MISS = 'MISS'
#     MS = 'MS'
#     DR = 'DR'
#     PROF = 'PROF'
#     REV = 'REV'
#     TITLE_CHOICES = (
#         (MR, 'Mr'),
#         (MRS, 'Mrs'),
#         (MISS, 'Miss'),
#         (MS, 'Ms'),
#         (DR, 'Dr'),
#         (PROF, 'Prof'),
#         (REV, 'Rev'),
#     )
# 
# 
#     class Meta(User.Meta):
#         verbose_name = 'Customer'
#         verbose_name_plural = 'Customers'
# 
# 
#     objects = CustomerManager()
# 
#     title = models.CharField(
#         max_length=4,
#         choices=TITLE_CHOICES,
#         default=MRS,
#     )
#     phone = models.CharField(
#         max_length=20,
#         validators=[phoneValidator],
#         blank=True,
#         null=True)
#     date_of_birth = models.DateField(blank=True, null=True)
#     gender = models.CharField(
#         max_length=1,
#         choices=GENDER_CHOICES,
#         default=FEMALE,
#     )
#     notes = models.TextField(blank=True)
# 
# 
#     def natural_key(self):
#         """
#         Serialisation aid. Not needed ATM.
#         """
#         return (self.username,)
# 
# 
#     def age(self):
#         """
#         Age to the nearest year.
#         """
#         if self.date_of_birth:
#             now = timezone.now()
#             return now.year - self.date_of_birth.year
#         return None
# 
# 
#     def __str__(self):
#         return '{0} {1}'.format(self.first_name, self.last_name)


# Path: diary/backends.py
from django.contrib.auth.backends import ModelBackend
from django.contrib.auth.models import User
from .models import Customer



class CustomerAuthBackend(ModelBackend):
    """
    Home-spun backend in response to django-model-utils functionality not
    working for Django >~ 2
    """
    def get_user(self, user_id):
        try:

            return Customer.get(pk=user_id)