1010from django .contrib .contenttypes .models import ContentTypeManager
1111from django .db import models
1212from django .utils import timezone
13- from django .utils .encoding import smart_str
1413from django .utils .translation import gettext_lazy as _
1514from mongoengine import ImproperlyConfigured
1615
1716from django_mongoengine import document , fields
1817from django_mongoengine .queryset import QuerySetManager
1918
19+ from django .contrib .auth .hashers import check_password , make_password
2020from .managers import MongoUserManager
2121
2222
@@ -34,32 +34,6 @@ def ct_init(self, *args, **kwargs):
3434 ),
3535)
3636
37- try :
38- from django .contrib .auth .hashers import check_password , make_password
39- except ImportError :
40- """Handle older versions of Django"""
41- from django .utils .hashcompat import md5_constructor , sha_constructor
42-
43- def get_hexdigest (algorithm , salt , raw_password ):
44- raw_password , salt = smart_str (raw_password ), smart_str (salt )
45- if algorithm == 'md5' :
46- return md5_constructor (salt + raw_password ).hexdigest ()
47- elif algorithm == 'sha1' :
48- return sha_constructor (salt + raw_password ).hexdigest ()
49- raise ValueError ('Got unknown password algorithm type in password' )
50-
51- def check_password (raw_password , password ):
52- algo , salt , hash = password .split ('$' )
53- return hash == get_hexdigest (algo , salt , raw_password )
54-
55- def make_password (raw_password ):
56- from random import random
57-
58- algo = 'sha1'
59- salt = get_hexdigest (algo , str (random ()), str (random ()))[:5 ]
60- hash = get_hexdigest (algo , salt , raw_password )
61- return '%s$%s$%s' % (algo , salt , hash )
62-
6337
6438class BaseUser :
6539 is_anonymous = AbstractBaseUser .__dict__ ['is_anonymous' ]
@@ -88,7 +62,7 @@ class Meta:
8862 # ordering = ('name',)
8963 # unique_together = (('app_label', 'model'),)
9064
91- def __unicode__ (self ):
65+ def __str__ (self ):
9266 return self .name
9367
9468 def model_class (self ):
@@ -158,7 +132,7 @@ class Meta:
158132 # unique_together = (('content_type', 'codename'),)
159133 # ordering = ('content_type__app_label', 'content_type__model', 'codename')
160134
161- def __unicode__ (self ):
135+ def __str__ (self ):
162136 return "%s | %s | %s" % (
163137 self .content_type .app_label ,
164138 self .content_type ,
@@ -195,7 +169,7 @@ class Meta:
195169 verbose_name = _ ('group' )
196170 verbose_name_plural = _ ('groups' )
197171
198- def __unicode__ (self ):
172+ def __str__ (self ):
199173 return self .name
200174
201175
@@ -208,22 +182,23 @@ class AbstractUser(BaseUser, document.Document):
208182 max_length = 150 ,
209183 verbose_name = _ ('username' ),
210184 help_text = _ ("Required. 150 characters or fewer. Letters, numbers and @/./+/-/_ characters" ),
185+ required = True ,
211186 )
212187
213188 first_name = fields .StringField (
214189 max_length = 30 ,
215- blank = True ,
216190 verbose_name = _ ('first name' ),
217191 )
218192
219- last_name = fields .StringField (max_length = 30 , blank = True , verbose_name = _ ('last name' ))
220- email = fields .EmailField (verbose_name = _ ('e-mail address' ), blank = True )
193+ last_name = fields .StringField (max_length = 30 , verbose_name = _ ('last name' ))
194+ email = fields .EmailField (verbose_name = _ ('e-mail address' ), required = True )
221195 password = fields .StringField (
222196 max_length = 128 ,
223197 verbose_name = _ ('password' ),
224198 help_text = _ (
225199 "Use '[algo]$[iterations]$[salt]$[hexdigest]' or use the <a href=\" password/\" >change password form</a>."
226200 ),
201+ required = True ,
227202 )
228203 is_staff = fields .BooleanField (
229204 default = False ,
@@ -250,7 +225,6 @@ class AbstractUser(BaseUser, document.Document):
250225 user_permissions = fields .ListField (
251226 fields .ReferenceField (Permission ),
252227 verbose_name = _ ('user permissions' ),
253- blank = True ,
254228 help_text = _ ('Permissions for the user.' ),
255229 )
256230
@@ -259,7 +233,7 @@ class AbstractUser(BaseUser, document.Document):
259233
260234 meta = {'abstract' : True , 'indexes' : [{'fields' : ['username' ], 'unique' : True , 'sparse' : True }]}
261235
262- def __unicode__ (self ):
236+ def __str__ (self ):
263237 return self .username
264238
265239 def get_full_name (self ):
0 commit comments