From 994ffaf117fc50aaf4c4f7ae122dcb8b52138d1c Mon Sep 17 00:00:00 2001 From: "M.Ravi" <mondi.ravi@gmail.com> Date: Fri, 22 Sep 2017 12:01:09 +0200 Subject: [PATCH] Send account details in email --- .../datacenterlight/emails/user_activation.html | 8 ++++++++ .../templates/datacenterlight/emails/user_activation.txt | 9 +++++++++ datacenterlight/views.py | 3 ++- membership/models.py | 9 ++++++--- 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/datacenterlight/templates/datacenterlight/emails/user_activation.html b/datacenterlight/templates/datacenterlight/emails/user_activation.html index 955eed18..2fac3632 100644 --- a/datacenterlight/templates/datacenterlight/emails/user_activation.html +++ b/datacenterlight/templates/datacenterlight/emails/user_activation.html @@ -10,5 +10,13 @@ You can activate your Data Center Light account by <a href="{{base_url}}{{activa You can also copy and paste the following link into the address bar of your browser<br/> to activate your Data Center Light account.<br/> {{base_url}}{{activation_link}} +{% if account_details %} +<br/><br/> +Your account details are as follows:<br/><br/> +Username : Your email address<br/> +Password : {{account_details}}<br/><br/> +You can reset your password here: +{% url 'hosting:reset_password' %} +{% endif %} {% endblocktrans %} {% endblock %} diff --git a/datacenterlight/templates/datacenterlight/emails/user_activation.txt b/datacenterlight/templates/datacenterlight/emails/user_activation.txt index 84ec50a9..478434ad 100644 --- a/datacenterlight/templates/datacenterlight/emails/user_activation.txt +++ b/datacenterlight/templates/datacenterlight/emails/user_activation.txt @@ -6,5 +6,14 @@ You can also copy and paste the following link into the address bar of your browser to activate your Data Center Light account. {{base_url}}{{activation_link}} +{% if account_details %} +Your account details are as follows: + +Username : Your email address +Password : {{account_details}} + +You can reset your password here: +{% url 'hosting:reset_password' %} +{% endif %} {% endblocktrans %} {% endblock %} diff --git a/datacenterlight/views.py b/datacenterlight/views.py index 0d373113..63842c56 100644 --- a/datacenterlight/views.py +++ b/datacenterlight/views.py @@ -598,7 +598,8 @@ class OrderConfirmationView(DetailView): custom_user = CustomUser.register( user.get('name'), password, user.get('email'), - app='dcl', base_url=None, send_email=False + app='dcl', base_url=None, send_email=True, + account_details=password ) logger.debug("Created user {}.".format(user.get('email'))) stripe_customer = StripeCustomer.objects. \ diff --git a/membership/models.py b/membership/models.py index 1be441b2..d3f6372a 100644 --- a/membership/models.py +++ b/membership/models.py @@ -82,7 +82,7 @@ class CustomUser(AbstractBaseUser, PermissionsMixin): @classmethod def register(cls, name, password, email, app='digital_glarus', - base_url=None, send_email=True): + base_url=None, send_email=True, account_details=None): user = cls.objects.filter(email=email).first() if not user: user = cls.objects.create_user(name=name, email=email, @@ -112,6 +112,9 @@ class CustomUser(AbstractBaseUser, PermissionsMixin): 'template_name': 'user_activation', 'template_path': 'datacenterlight/emails/' } + if account_details: + email_data['context'][ + 'account_details'] = account_details email = BaseEmail(**email_data) email.send() return user @@ -177,7 +180,8 @@ class StripeCustomer(models.Model): return "%s - %s" % (self.stripe_id, self.user.email) @classmethod - def create_stripe_api_customer(cls, email=None, token=None, customer_name=None): + def create_stripe_api_customer(cls, email=None, token=None, + customer_name=None): """ This method creates a Stripe API customer with the given email, token and customer_name. This is different from @@ -194,7 +198,6 @@ class StripeCustomer(models.Model): else: return None - @classmethod def get_or_create(cls, email=None, token=None): """