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,6 +84,7 @@ 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
|
||||||
|
if send_email is True:
|
||||||
email_data = {
|
email_data = {
|
||||||
'subject': _('Activate your Data Center Light account'),
|
'subject': _('Activate your Data Center Light account'),
|
||||||
'from_address': '(Data Center Light) Data Center Light Support <support@datacenterlight.ch>',
|
'from_address': '(Data Center Light) Data Center Light Support <support@datacenterlight.ch>',
|
||||||
|
@ -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