# Path: coffeestats/caffeine/models.py
# class User(AbstractUser):
#     """
#     User model.
# 
#     """
# 
#     cryptsum = models.CharField(_("old password hash"), max_length=60, blank=True)
#     location = models.CharField(max_length=128, blank=True)
#     public = models.BooleanField(default=True)
#     token = models.CharField(max_length=32, unique=True)
#     timezone = models.CharField(_("timezone"), max_length=40, db_index=True, blank=True)
# 
#     objects = CaffeineUserManager()
# 
#     def get_absolute_url(self):
#         return reverse("public", kwargs={"username": self.username})
# 
#     def __str__(self):
#         return self.get_full_name() or self.username
# 
#     def export_csv(self):
#         subject = _("Your caffeine records")
#         body = _("Attached is your caffeine track record.")
#         email = EmailMessage(subject, body, to=[self.email])
#         now = timezone.now().strftime(settings.CAFFEINE_DATETIME_FORMAT)
#         for drink in ("coffee", "mate"):
#             email.attachments.append(
#                 (
#                     "%s-%s.csv" % (drink, now),
#                     Caffeine.objects.get_csv_data(getattr(DRINK_TYPES, drink), self),
#                     "text/csv",
#                 )
#             )
#         email.send()
# 
#     def has_usable_password(self):
#         """
#         Checks whether the current user has either an old password hash or a
#         valid new password hash.
# 
#         """
#         return self.cryptsum or super(User, self).has_usable_password()
# 
#     def set_password(self, password):
#         """
#         Sets the password and creates the authentication token if it is not
#         set.
# 
#         """
#         super(User, self).set_password(password)
#         if not self.token:
#             # on the run token
#             # TODO: use something better for API authentication
#             self.token = md5((self.username + password).encode("utf8")).hexdigest()


from passlib.hash import bcrypt
from django.utils import timezone
from django.contrib.auth.hashers import make_password
from .models import User
import logging
"""
Custom authentication backend for coffeestats.

"""





logger = logging.getLogger(__name__)


class LegacyCoffeestatsAuth(object):
    """
    Authentication backend for passwords generated by the original coffeestats
    PHP implementation.

    """

    def authenticate(self, username=None, password=None):
        try:
            user = User.objects.get(username=username)

# Path: coffeestats/caffeine/models.py
# class User(AbstractUser):
#     """
#     User model.
# 
#     """
# 
#     cryptsum = models.CharField(_("old password hash"), max_length=60, blank=True)
#     location = models.CharField(max_length=128, blank=True)
#     public = models.BooleanField(default=True)
#     token = models.CharField(max_length=32, unique=True)
#     timezone = models.CharField(_("timezone"), max_length=40, db_index=True, blank=True)
# 
#     objects = CaffeineUserManager()
# 
#     def get_absolute_url(self):
#         return reverse("public", kwargs={"username": self.username})
# 
#     def __str__(self):
#         return self.get_full_name() or self.username
# 
#     def export_csv(self):
#         subject = _("Your caffeine records")
#         body = _("Attached is your caffeine track record.")
#         email = EmailMessage(subject, body, to=[self.email])
#         now = timezone.now().strftime(settings.CAFFEINE_DATETIME_FORMAT)
#         for drink in ("coffee", "mate"):
#             email.attachments.append(
#                 (
#                     "%s-%s.csv" % (drink, now),
#                     Caffeine.objects.get_csv_data(getattr(DRINK_TYPES, drink), self),
#                     "text/csv",
#                 )
#             )
#         email.send()
# 
#     def has_usable_password(self):
#         """
#         Checks whether the current user has either an old password hash or a
#         valid new password hash.
# 
#         """
#         return self.cryptsum or super(User, self).has_usable_password()
# 
#     def set_password(self, password):
#         """
#         Sets the password and creates the authentication token if it is not
#         set.
# 
#         """
#         super(User, self).set_password(password)
#         if not self.token:
#             # on the run token
#             # TODO: use something better for API authentication
#             self.token = md5((self.username + password).encode("utf8")).hexdigest()


# Path: coffeestats/caffeine/authbackend.py
from passlib.hash import bcrypt
from django.utils import timezone
from django.contrib.auth.hashers import make_password
from .models import User
import logging

"""
Custom authentication backend for coffeestats.

"""





logger = logging.getLogger(__name__)


class LegacyCoffeestatsAuth(object):
    """
    Authentication backend for passwords generated by the original coffeestats
    PHP implementation.

    """

    def authenticate(self, username=None, password=None):
        try:
            user = User.objects.get(username=username)

        except User.DoesNotExist: