"""
Abstract models related to password management.
"""
# Imports
from django.conf import settings
from django.db import models
from django.utils.translation import ugettext_lazy as _
from superdjango.db.datetime.fields import AutoNowAddDateTimeField
# Exports
__all__ = (
"PasswordResetHistoryModel",
)
# Constants
AUTH_USER_MODEL = settings.AUTH_USER_MODEL
# Models
[docs]class PasswordResetHistoryModel(models.Model):
"""Record password reset attempts."""
added_dt = AutoNowAddDateTimeField(
_("added date/time"),
help_text=_("Date and time the record was created."),
)
email = models.EmailField(
_("email"),
db_index=True,
help_text=_("The email address of the requested attempt.")
)
http_accept = models.CharField(
_("HTTP accept"),
blank=True,
help_text=_("The HTTP accept header of the requested attempt."),
max_length=1025
)
ip_address = models.GenericIPAddressField(
_("ip address"),
blank=True,
help_text=_("The IP address of the visitor."),
null=True
)
success = models.BooleanField(
_("success"),
help_text=_("Indicates a matching user was found.")
)
user_agent = models.CharField(
_("user agent"),
blank=True,
help_text=_("The user agent of the requested attempt."),
max_length=255,
)
username = models.CharField(
_("username"),
blank=True,
help_text=_("The user name to which the reset pertains."),
max_length=255
)
class Meta:
abstract = True
def __str__(self):
return self.label
@property
def label(self):
"""Get a label for the record.
:rtype: str
"""
a = list()
a.append(self.added_dt)
a.append(self.email)
if self.username:
a.append("(%s)" % self.username)
return " ".join(a)