0001-misc-add-User.set_random_password-47943.patch
src/authentic2/custom_user/models.py | ||
---|---|---|
19 | 19 | |
20 | 20 |
import datetime |
21 | 21 |
import random |
22 |
import secrets |
|
22 | 23 | |
23 | 24 |
from django.db import models, transaction |
24 | 25 |
from django.utils import timezone |
... | ... | |
371 | 372 |
if save: |
372 | 373 |
self.save(update_fields=['email', 'email_verified', 'is_active', 'deleted']) |
373 | 374 | |
375 |
def set_random_password(self): |
|
376 |
self.set_password(secrets.token_urlsafe()) |
|
377 | ||
374 | 378 | |
375 | 379 |
class DeletedUser(models.Model): |
376 | 380 |
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 |
- |