Commit 0816569e77eb90e1df81bed8062c927fc4a209f2
Committed by
Sergio Oliveira
1 parent
63e58c83
Exists in
master
and in
39 other branches
Created user manager to create users with password
Now users are created with valid password whether they werre created by browserid or not Signed-off-by: Carlos Oliveira <carlospecter@gmail.com> Signed-off-by: Alexandre Almeida <alexandreab@live.com> Signed-off-by: Sergio Campos <sergio@tracy.com.br>
Showing
1 changed file
with
17 additions
and
1 deletions
Show diff stats
colab/accounts/models.py
... | ... | @@ -3,14 +3,28 @@ |
3 | 3 | import urlparse |
4 | 4 | |
5 | 5 | from django.db import models |
6 | -from django.contrib.auth.models import AbstractUser | |
6 | +from django.contrib.auth.models import AbstractUser, UserManager | |
7 | 7 | from django.core import validators |
8 | 8 | from django.core.urlresolvers import reverse |
9 | +from django.utils.crypto import get_random_string | |
9 | 10 | from django.utils.translation import ugettext_lazy as _ |
10 | 11 | |
11 | 12 | from .utils import mailman |
12 | 13 | |
13 | 14 | |
15 | +class ColabUserManager(UserManager): | |
16 | + | |
17 | + def create_user(self, username, email=None, password=None, **extra_fields): | |
18 | + | |
19 | + # It creates a valid password for users | |
20 | + if not password: | |
21 | + password = get_random_string() | |
22 | + | |
23 | + return super(ColabUserManager, self).create_user(username, email, | |
24 | + password, | |
25 | + **extra_fields) | |
26 | + | |
27 | + | |
14 | 28 | class User(AbstractUser): |
15 | 29 | """ |
16 | 30 | For more information about AbstractUser |
... | ... | @@ -31,6 +45,8 @@ class User(AbstractUser): |
31 | 45 | bio = models.CharField(max_length=200, null=True, blank=True) |
32 | 46 | needs_update = models.BooleanField(default=True) |
33 | 47 | |
48 | + objects = ColabUserManager() | |
49 | + | |
34 | 50 | def check_password(self, raw_password): |
35 | 51 | |
36 | 52 | if self.xmpp.exists() and raw_password == self.xmpp.first().password: | ... | ... |