Hide keyboard shortcuts

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. 

3 

4""" 

5 

6# Imports 

7 

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 

12 

13# Exports 

14 

15__all__ = ( 

16 "PasswordResetHistoryModel", 

17) 

18 

19# Constants 

20 

21AUTH_USER_MODEL = settings.AUTH_USER_MODEL 

22 

23# Models 

24 

25 

26class PasswordResetHistoryModel(models.Model): 

27 """Record password reset attempts.""" 

28 

29 added_dt = AutoNowAddDateTimeField( 

30 _("added date/time"), 

31 help_text=_("Date and time the record was created."), 

32 ) 

33 

34 email = models.EmailField( 

35 _("email"), 

36 db_index=True, 

37 help_text=_("The email address of the requested attempt.") 

38 ) 

39 

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 ) 

46 

47 ip_address = models.GenericIPAddressField( 

48 _("ip address"), 

49 blank=True, 

50 help_text=_("The IP address of the visitor."), 

51 null=True 

52 ) 

53 

54 success = models.BooleanField( 

55 _("success"), 

56 help_text=_("Indicates a matching user was found.") 

57 ) 

58 

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 ) 

65 

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 ) 

72 

73 class Meta: 

74 abstract = True 

75 

76 def __str__(self): 

77 return self.label 

78 

79 @property 

80 def label(self): 

81 """Get a label for the record. 

82 

83 :rtype: str 

84 

85 """ 

86 a = list() 

87 a.append(self.added_dt) 

88 a.append(self.email) 

89 

90 if self.username: 

91 a.append("(%s)" % self.username) 

92 

93 return " ".join(a)