implement test for User.set_password, add Shadow.set_password
This commit is contained in:
parent
df9800b827
commit
83562ba2bf
2 changed files with 26 additions and 3 deletions
|
@ -221,6 +221,7 @@ class User(TimeStampedModel, models.Model):
|
|||
return '{0} ({1})'.format(self.username, self.uid)
|
||||
|
||||
def set_password(self, password):
|
||||
self.shadow.set_password(password)
|
||||
UserTaskResult.objects.create_usertaskresult(
|
||||
self,
|
||||
create_ldap_user.delay(
|
||||
|
@ -289,12 +290,12 @@ class ShadowManager(models.Manager):
|
|||
|
||||
def create_shadow(self, user, password):
|
||||
changedays = (timezone.now().date() - date(1970, 1, 1)).days
|
||||
pwhash = sha512_crypt.encrypt(password)
|
||||
shadow = self.create(
|
||||
user=user, changedays=changedays,
|
||||
minage=0, maxage=None, gracedays=7,
|
||||
inactdays=30, expiredays=None, passwd=pwhash
|
||||
inactdays=30, expiredays=None
|
||||
)
|
||||
shadow.set_password(password)
|
||||
shadow.save()
|
||||
return shadow
|
||||
|
||||
|
@ -342,6 +343,9 @@ class Shadow(TimeStampedModel, models.Model):
|
|||
def __str__(self):
|
||||
return 'for user {0}'.format(self.user)
|
||||
|
||||
def set_password(self, password):
|
||||
self.passwd = sha512_crypt.encrypt(password)
|
||||
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class AdditionalGroup(TimeStampedModel, models.Model):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue