Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""
2Abstract models related to password management.
4"""
6# Imports
8from django.conf import settings
9from django.db import models
10from django.utils.translation import ugettext_lazy as _
11from superdjango.db.datetime.fields import AutoNowAddDateTimeField
13# Exports
15__all__ = (
16 "PasswordResetHistoryModel",
17)
19# Constants
21AUTH_USER_MODEL = settings.AUTH_USER_MODEL
23# Models
26class PasswordResetHistoryModel(models.Model):
27 """Record password reset attempts."""
29 added_dt = AutoNowAddDateTimeField(
30 _("added date/time"),
31 help_text=_("Date and time the record was created."),
32 )
34 email = models.EmailField(
35 _("email"),
36 db_index=True,
37 help_text=_("The email address of the requested attempt.")
38 )
40 http_accept = models.CharField(
41 _("HTTP accept"),
42 blank=True,
43 help_text=_("The HTTP accept header of the requested attempt."),
44 max_length=1025
45 )
47 ip_address = models.GenericIPAddressField(
48 _("ip address"),
49 blank=True,
50 help_text=_("The IP address of the visitor."),
51 null=True
52 )
54 success = models.BooleanField(
55 _("success"),
56 help_text=_("Indicates a matching user was found.")
57 )
59 user_agent = models.CharField(
60 _("user agent"),
61 blank=True,
62 help_text=_("The user agent of the requested attempt."),
63 max_length=255,
64 )
66 username = models.CharField(
67 _("username"),
68 blank=True,
69 help_text=_("The user name to which the reset pertains."),
70 max_length=255
71 )
73 class Meta:
74 abstract = True
76 def __str__(self):
77 return self.label
79 @property
80 def label(self):
81 """Get a label for the record.
83 :rtype: str
85 """
86 a = list()
87 a.append(self.added_dt)
88 a.append(self.email)
90 if self.username:
91 a.append("(%s)" % self.username)
93 return " ".join(a)