From 0816569e77eb90e1df81bed8062c927fc4a209f2 Mon Sep 17 00:00:00 2001 From: Carlos Oliveira Date: Thu, 22 Jan 2015 15:31:29 -0200 Subject: [PATCH] Created user manager to create users with password --- colab/accounts/models.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/colab/accounts/models.py b/colab/accounts/models.py index 0abd225..7a7a00e 100644 --- a/colab/accounts/models.py +++ b/colab/accounts/models.py @@ -3,14 +3,28 @@ import urlparse from django.db import models -from django.contrib.auth.models import AbstractUser +from django.contrib.auth.models import AbstractUser, UserManager from django.core import validators from django.core.urlresolvers import reverse +from django.utils.crypto import get_random_string from django.utils.translation import ugettext_lazy as _ from .utils import mailman +class ColabUserManager(UserManager): + + def create_user(self, username, email=None, password=None, **extra_fields): + + # It creates a valid password for users + if not password: + password = get_random_string() + + return super(ColabUserManager, self).create_user(username, email, + password, + **extra_fields) + + class User(AbstractUser): """ For more information about AbstractUser @@ -31,6 +45,8 @@ class User(AbstractUser): bio = models.CharField(max_length=200, null=True, blank=True) needs_update = models.BooleanField(default=True) + objects = ColabUserManager() + def check_password(self, raw_password): if self.xmpp.exists() and raw_password == self.xmpp.first().password: -- libgit2 0.21.2