From 6004a7ede40f23bb57adc2f273790e70cc0b50ab Mon Sep 17 00:00:00 2001
From: Arvind Tiwari <tiwariav@gmail.com>
Date: Sat, 23 Sep 2017 01:03:43 +0530
Subject: [PATCH] new welcome email

---
 .../datacenterlight/emails/welcome_user.html  | 45 +++++++++++++++++++
 .../datacenterlight/emails/welcome_user.txt   |  9 ++++
 datacenterlight/urls.py                       | 12 +++--
 hosting/views.py                              | 23 +++++++++-
 4 files changed, 84 insertions(+), 5 deletions(-)
 create mode 100644 datacenterlight/templates/datacenterlight/emails/welcome_user.html
 create mode 100644 datacenterlight/templates/datacenterlight/emails/welcome_user.txt

diff --git a/datacenterlight/templates/datacenterlight/emails/welcome_user.html b/datacenterlight/templates/datacenterlight/emails/welcome_user.html
new file mode 100644
index 00000000..be90f9b8
--- /dev/null
+++ b/datacenterlight/templates/datacenterlight/emails/welcome_user.html
@@ -0,0 +1,45 @@
+{% load static i18n %}
+<!DOCTYPE html>
+<html>
+
+<head>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1">
+    <title>{% trans "Welcome to Data Center Light!" %}</title>
+    <link rel="shortcut icon" href="{% static 'datacenterlight/img/favicon.ico' %}" type="image/x-icon">
+    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lato:300,400">
+</head>
+
+<body style="margin: 0; padding: 20px 0;">
+    <table style="width: 100%; margin: auto; border-spacing: 0; border-collapse: collapse; max-width: 560px; border: 1px solid #aaa;">
+        <tr>
+            <td style="padding-top: 25px; padding-left: 22px; padding-right: 30px; font-family: Lato, Arial, sans-serif;">
+                <img src="{{base_url}}{% static 'datacenterlight/img/logo_black.svg' %}" style="vertical-align: middle; width: 200px; height: 50px;">
+            </td>
+        </tr>
+        <tr>
+            <td style="padding-top: 15px; padding-left: 30px; padding-right: 30px;">
+                <h1 style="font-family: Lato, Arial, sans-serif; font-size: 25px; font-weight: 400; margin: 0;">{% trans "Welcome to Data Center Light!" %}</h1>
+            </td>
+        </tr>
+        <tr>
+            <td style="padding-top: 25px; padding-left: 30px; padding-right: 30px;">
+                <p style="line-height: 1.6; font-family: Lato, Arial, sans-serif; font-weight: 300; margin: 0;">
+                    {% blocktrans %}Thanks for joining us! We provide the most affordable virtual machines from the heart of Switzerland.<br>Try now, order a VM. VM price starts from only 15CHF per month.{% endblocktrans %}
+                </p>
+            </td>
+        </tr>
+        <tr>
+            <td style="padding-top: 20px; padding-left: 30px; padding-right: 30px;">
+                <a class="btn" href="{{ base_url }}{% url 'hosting:create_virtual_machine' %}" style="font-family: Lato, Arial, sans-serif; text-decoration: none; background-color: #1596da; color: #fff; padding-top: 10px; padding-bottom: 10px; padding-left: 30px; padding-right: 30px; letter-spacing: 0.5px; border-radius: 3px; display: inline-block;">{% trans "ORDER VM" %}</a>
+            </td>
+        </tr>
+        <tr>
+            <td style="padding-top: 40px; padding-left: 30px; padding-right: 30px; padding-bottom: 25px;">
+                <h3 style="font-family: Lato, Arial, sans-serif; margin: 0; font-weight: 400; font-size: 18px;">Your Data Center Light Team</h3>
+            </td>
+        </tr>
+    </table>
+</body>
+
+</html>
\ No newline at end of file
diff --git a/datacenterlight/templates/datacenterlight/emails/welcome_user.txt b/datacenterlight/templates/datacenterlight/emails/welcome_user.txt
new file mode 100644
index 00000000..59fc242b
--- /dev/null
+++ b/datacenterlight/templates/datacenterlight/emails/welcome_user.txt
@@ -0,0 +1,9 @@
+{% load static i18n %}
+
+{% trans "Welcome to Data Center Light!" %}
+
+{% blocktrans %}Thanks for joining us! We provide the most affordable virtual machines from the heart of Switzerland.<br>Try now, order a VM. VM price starts from only 15CHF per month.{% endblocktrans %}
+
+{{ base_url }}{% url 'hosting:create_virtual_machine' %}
+
+Your Data Center Light Team
\ No newline at end of file
diff --git a/datacenterlight/urls.py b/datacenterlight/urls.py
index 772e691d..8f0bf646 100644
--- a/datacenterlight/urls.py
+++ b/datacenterlight/urls.py
@@ -1,11 +1,17 @@
 from django.conf.urls import url
 
-from .views import IndexView, BetaProgramView, LandingProgramView, \
-    BetaAccessView, PricingView, SuccessView, \
-    PaymentOrderView, OrderConfirmationView, \
+from .views import (
+    IndexView, BetaProgramView, LandingProgramView, BetaAccessView,
+    PricingView, SuccessView, PaymentOrderView, OrderConfirmationView,
     WhyDataCenterLightView, ContactUsView
+)
+
+from django.views.generic import TemplateView
+
 
 urlpatterns = [
+    url(r'^test/$', TemplateView.as_view(
+        template_name='datacenterlight/emails/welcome_user.html')),
     url(r'^$', IndexView.as_view(), name='index'),
     url(r'^t/$', IndexView.as_view(), name='index_t'),
     url(r'^g/$', IndexView.as_view(), name='index_g'),
diff --git a/hosting/views.py b/hosting/views.py
index e1d2feb2..4272afe9 100644
--- a/hosting/views.py
+++ b/hosting/views.py
@@ -255,12 +255,31 @@ class SignupValidatedView(SignupValidateView):
         login_url = '<a href="' + \
                     reverse('hosting:login') + '">' + str(_('login')) + '</a>'
         section_title = _('Account activation')
+        user = CustomUser.objects.filter(
+            validation_slug=self.kwargs['validate_slug']).first()
+        pre_valid = user.validated
         if validated:
             message = '{account_activation_string} <br /> {login_string} {lurl}.'.format(
                 account_activation_string=_(
                     "Your account has been activated."),
                 login_string=_("You can now"),
                 lurl=login_url)
+            if not pre_valid:
+                email_data = {
+                    'subject': 'Welcome to Data Center Light!',
+                    'to': self.request.user.email,
+                    'context': {
+                        'base_url': "{0}://{1}".format(
+                            self.request.scheme,
+                            self.request.get_host()
+                        )
+                    },
+                    'template_name': 'welcome_user',
+                    'template_path': 'datacenterlight/emails/',
+                    'from_address': settings.DCL_SUPPORT_FROM_ADDRESS,
+                }
+                email = BaseEmail(**email_data)
+                email.send()
         else:
             home_url = '<a href="' + \
                        reverse('datacenterlight:index') + \
@@ -775,8 +794,8 @@ class OrdersHostingDetailView(LoginRequiredMixin,
             'redirect': reverse('hosting:virtual_machines'),
             'msg_title': str(_('Thank you for the order.')),
             'msg_body': str(_('Your VM will be up and running in a few moments.'
-                          ' We will send you a confirmation email as soon as'
-                          ' it is ready.'))
+                              ' We will send you a confirmation email as soon as'
+                              ' it is ready.'))
         }
 
         return HttpResponse(json.dumps(response),