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.contrib.auth.models import User
|
||||
from django.contrib.sites.models import Site
|
||||
from django.utils.crypto import get_random_string
|
||||
|
||||
from utils.stripe_utils import StripeUtils
|
||||
from utils.mailer import DigitalGlarusRegistrationMailer
|
||||
|
@ -73,7 +74,7 @@ class CustomUser(AbstractBaseUser, PermissionsMixin):
|
|||
REQUIRED_FIELDS = ['name', 'password']
|
||||
|
||||
@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()
|
||||
if not user:
|
||||
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)
|
||||
elif app == 'dcl':
|
||||
user.is_active = False
|
||||
email_data = {
|
||||
'subject': _('Activate your Data Center Light account'),
|
||||
'from_address': '(Data Center Light) Data Center Light Support <support@datacenterlight.ch>',
|
||||
'to': user.email,
|
||||
'context': {'base_url' : base_url,
|
||||
'activation_link' : reverse('hosting:validate', kwargs={'validate_slug': user.validation_slug})},
|
||||
'template_name': 'user_activation',
|
||||
'template_path': 'datacenterlight/emails/'
|
||||
}
|
||||
email = BaseEmail(**email_data)
|
||||
email.send()
|
||||
if send_email is True:
|
||||
email_data = {
|
||||
'subject': _('Activate your Data Center Light account'),
|
||||
'from_address': '(Data Center Light) Data Center Light Support <support@datacenterlight.ch>',
|
||||
'to': user.email,
|
||||
'context': {'base_url' : base_url,
|
||||
'activation_link' : reverse('hosting:validate', kwargs={'validate_slug': user.validation_slug})},
|
||||
'template_name': 'user_activation',
|
||||
'template_path': 'datacenterlight/emails/'
|
||||
}
|
||||
email = BaseEmail(**email_data)
|
||||
email.send()
|
||||
return user
|
||||
else:
|
||||
return None
|
||||
|
@ -113,6 +115,10 @@ class CustomUser(AbstractBaseUser, PermissionsMixin):
|
|||
return True
|
||||
return False
|
||||
|
||||
@classmethod
|
||||
def get_random_password(cls):
|
||||
return get_random_string(24)
|
||||
|
||||
def is_superuser(self):
|
||||
return False
|
||||
|
||||
|
|
Loading…
Reference in a new issue