|
19 | 19 | from django.template import loader |
20 | 20 | from django.urls import path |
21 | 21 | from django.urls import reverse |
| 22 | +from django.utils.crypto import get_random_string |
22 | 23 | from django.utils.translation import gettext as _ |
23 | 24 |
|
24 | 25 | from organizations.backends.forms import UserRegistrationForm |
|
28 | 29 | from organizations.utils import model_field_attr |
29 | 30 |
|
30 | 31 |
|
| 32 | +def make_random_password( |
| 33 | + length=10, |
| 34 | + allowed_chars="abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789", |
| 35 | +): |
| 36 | + """ |
| 37 | + Generate a random password with the given length and given |
| 38 | + allowed_chars. The default value of allowed_chars does not have "I" or |
| 39 | + "O" or letters and digits that look similar -- just to avoid confusion. |
| 40 | +
|
| 41 | + (Pulled directly from since-deprecated manager method in Django source) |
| 42 | + """ |
| 43 | + return get_random_string(length, allowed_chars) |
| 44 | + |
| 45 | + |
31 | 46 | class BaseBackend: |
32 | 47 | """ |
33 | 48 | Base backend class for registering and inviting users to an organization |
@@ -215,7 +230,7 @@ def register_by_email(self, email, sender=None, request=None, **kwargs): |
215 | 230 | user = self.user_model.objects.create( |
216 | 231 | username=self.get_username(), |
217 | 232 | email=email, |
218 | | - password=self.user_model.objects.make_random_password(), |
| 233 | + password=make_random_password(), |
219 | 234 | ) |
220 | 235 | user.is_active = False |
221 | 236 | user.save() |
@@ -248,7 +263,7 @@ def create_view(self, request): |
248 | 263 | user = self.user_model.objects.create( |
249 | 264 | username=self.get_username(), |
250 | 265 | email=form.cleaned_data["email"], |
251 | | - password=self.user_model.objects.make_random_password(), |
| 266 | + password=make_random_password(), |
252 | 267 | ) |
253 | 268 | user.is_active = False |
254 | 269 | user.save() |
@@ -317,11 +332,11 @@ def invite_by_email(self, email, sender=None, request=None, **kwargs): |
317 | 332 | user = self.user_model.objects.create( |
318 | 333 | username=self.get_username(), |
319 | 334 | email=email, |
320 | | - password=self.user_model.objects.make_random_password(), |
| 335 | + password=make_random_password(), |
321 | 336 | ) |
322 | 337 | else: |
323 | 338 | user = self.user_model.objects.create( |
324 | | - email=email, password=self.user_model.objects.make_random_password() |
| 339 | + email=email, password=make_random_password() |
325 | 340 | ) |
326 | 341 | user.is_active = False |
327 | 342 | user.save() |
|
0 commit comments