Added send_email flag to send/not send email on user registration. Added get_random_password method to CustomUser
This commit is contained in:
parent
c4c110b506
commit
b4c3172a4d
1 changed files with 18 additions and 12 deletions
|
@ -6,6 +6,7 @@ from django.contrib.auth.hashers import make_password
|
||||||
from django.core.validators import RegexValidator
|
from django.core.validators import RegexValidator
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.contrib.sites.models import Site
|
from django.contrib.sites.models import Site
|
||||||
|
from django.utils.crypto import get_random_string
|
||||||
|
|
||||||
from utils.stripe_utils import StripeUtils
|
from utils.stripe_utils import StripeUtils
|
||||||
from utils.mailer import DigitalGlarusRegistrationMailer
|
from utils.mailer import DigitalGlarusRegistrationMailer
|
||||||
|
@ -73,7 +74,7 @@ class CustomUser(AbstractBaseUser, PermissionsMixin):
|
||||||
REQUIRED_FIELDS = ['name', 'password']
|
REQUIRED_FIELDS = ['name', 'password']
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def register(cls, name, password, email, app='digital_glarus', base_url=None):
|
def register(cls, name, password, email, app='digital_glarus', base_url=None, send_email=True):
|
||||||
user = cls.objects.filter(email=email).first()
|
user = cls.objects.filter(email=email).first()
|
||||||
if not user:
|
if not user:
|
||||||
user = cls.objects.create_user(name=name, email=email, password=password)
|
user = cls.objects.create_user(name=name, email=email, password=password)
|
||||||
|
@ -83,17 +84,18 @@ class CustomUser(AbstractBaseUser, PermissionsMixin):
|
||||||
dg.send_mail(to=user.email)
|
dg.send_mail(to=user.email)
|
||||||
elif app == 'dcl':
|
elif app == 'dcl':
|
||||||
user.is_active = False
|
user.is_active = False
|
||||||
email_data = {
|
if send_email is True:
|
||||||
'subject': _('Activate your Data Center Light account'),
|
email_data = {
|
||||||
'from_address': '(Data Center Light) Data Center Light Support <support@datacenterlight.ch>',
|
'subject': _('Activate your Data Center Light account'),
|
||||||
'to': user.email,
|
'from_address': '(Data Center Light) Data Center Light Support <support@datacenterlight.ch>',
|
||||||
'context': {'base_url' : base_url,
|
'to': user.email,
|
||||||
'activation_link' : reverse('hosting:validate', kwargs={'validate_slug': user.validation_slug})},
|
'context': {'base_url' : base_url,
|
||||||
'template_name': 'user_activation',
|
'activation_link' : reverse('hosting:validate', kwargs={'validate_slug': user.validation_slug})},
|
||||||
'template_path': 'datacenterlight/emails/'
|
'template_name': 'user_activation',
|
||||||
}
|
'template_path': 'datacenterlight/emails/'
|
||||||
email = BaseEmail(**email_data)
|
}
|
||||||
email.send()
|
email = BaseEmail(**email_data)
|
||||||
|
email.send()
|
||||||
return user
|
return user
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
@ -113,6 +115,10 @@ class CustomUser(AbstractBaseUser, PermissionsMixin):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_random_password(cls):
|
||||||
|
return get_random_string(24)
|
||||||
|
|
||||||
def is_superuser(self):
|
def is_superuser(self):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue