0001-misc-add-User.set_random_password-47943.patch
src/authentic2/custom_user/models.py | ||
---|---|---|
17 | 17 | |
18 | 18 |
from __future__ import unicode_literals |
19 | 19 | |
20 |
import base64 |
|
20 | 21 |
import datetime |
22 |
import os |
|
21 | 23 |
import random |
22 | 24 | |
23 | 25 |
from django.db import models, transaction |
... | ... | |
371 | 373 |
if save: |
372 | 374 |
self.save(update_fields=['email', 'email_verified', 'is_active', 'deleted']) |
373 | 375 | |
376 |
def set_random_password(self): |
|
377 |
self.set_password(base64.b64encode(os.urandom(32))) |
|
378 | ||
374 | 379 | |
375 | 380 |
class DeletedUser(models.Model): |
376 | 381 |
deleted = models.DateTimeField( |
tests/test_user_model.py | ||
---|---|---|
236 | 236 |
val1, val2 = attribute_values[:2] |
237 | 237 |
assert val1.attribute.label == 'phone' |
238 | 238 |
assert val2.attribute.label == 'birthdate' |
239 | ||
240 | ||
241 |
def test_set_random_password(): |
|
242 |
user = User() |
|
243 |
user.set_unusable_password() |
|
244 |
assert not user.has_usable_password() |
|
245 |
user.set_random_password() |
|
246 |
assert user.has_usable_password() |
|
239 |
- |