From 32e50112413793818a564a70fb122d15d668d3cc Mon Sep 17 00:00:00 2001 From: "M.Ravi" Date: Sun, 11 Jun 2017 05:08:13 +0530 Subject: [PATCH 1/8] Added user_activation email templates --- .../emails/user_activation.html | 129 ++++++++++++++++++ .../emails/user_activation.txt | 129 ++++++++++++++++++ 2 files changed, 258 insertions(+) create mode 100644 datacenterlight/templates/datacenterlight/emails/user_activation.html create mode 100644 datacenterlight/templates/datacenterlight/emails/user_activation.txt diff --git a/datacenterlight/templates/datacenterlight/emails/user_activation.html b/datacenterlight/templates/datacenterlight/emails/user_activation.html new file mode 100644 index 00000000..2948b797 --- /dev/null +++ b/datacenterlight/templates/datacenterlight/emails/user_activation.html @@ -0,0 +1,129 @@ +{% load static from staticfiles %} + + + + + + +Oxygen Invoice + + + + + + + + + + + + + +
+
+ + +
+ +
+ + + +
+ logo + +
+
+ +
+
+
+
+ + + + + + + + + + +
+ Datacenterlight user activation +
+

+ You can activate your datacenterlight account by clicking here.

+ You can also copy and paste the following link into the address bar of your browser and follow the link in order to activate your datacenterlight account.
+ {{base_url}}{{activation_link}} +

 
+
+
+
+ + +
Your data center light team
+
+
+
+ + + diff --git a/datacenterlight/templates/datacenterlight/emails/user_activation.txt b/datacenterlight/templates/datacenterlight/emails/user_activation.txt new file mode 100644 index 00000000..2948b797 --- /dev/null +++ b/datacenterlight/templates/datacenterlight/emails/user_activation.txt @@ -0,0 +1,129 @@ +{% load static from staticfiles %} + + + + + + +Oxygen Invoice + + + + + + + + + + + + + +
+
+ + +
+ +
+ + + +
+ logo + +
+
+ +
+
+
+
+ + + + + + + + + + +
+ Datacenterlight user activation +
+

+ You can activate your datacenterlight account by clicking here.

+ You can also copy and paste the following link into the address bar of your browser and follow the link in order to activate your datacenterlight account.
+ {{base_url}}{{activation_link}} +

 
+
+
+
+ + +
Your data center light team
+
+
+
+ + + From bd10d1cf9f560ca55c8280af323027c7a3d1a455 Mon Sep 17 00:00:00 2001 From: "M.Ravi" Date: Sun, 11 Jun 2017 05:10:00 +0530 Subject: [PATCH 2/8] Added signup_validate html template. This is an empty template that we use to show appropriate message during email confirmation --- .../templates/hosting/signup_validate.html | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 hosting/templates/hosting/signup_validate.html diff --git a/hosting/templates/hosting/signup_validate.html b/hosting/templates/hosting/signup_validate.html new file mode 100644 index 00000000..00b0561a --- /dev/null +++ b/hosting/templates/hosting/signup_validate.html @@ -0,0 +1,21 @@ +{% extends "hosting/base_short.html" %} +{% load staticfiles bootstrap3 i18n %} + +{% block content %} +
+
+
+
+

{% trans "Your VM hosted in Switzerland"%}

+
+
+ +
+
+
+{% endblock %} From b8463360b541a30c8094afb35b37029f16ebb579 Mon Sep 17 00:00:00 2001 From: "M.Ravi" Date: Sun, 11 Jun 2017 05:11:09 +0530 Subject: [PATCH 3/8] Added styles for message title and text for email confirmation --- hosting/static/hosting/css/landing-page.css | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/hosting/static/hosting/css/landing-page.css b/hosting/static/hosting/css/landing-page.css index 5d4c6a90..c6cf9169 100644 --- a/hosting/static/hosting/css/landing-page.css +++ b/hosting/static/hosting/css/landing-page.css @@ -317,6 +317,17 @@ h6 { padding: 15px 20px 0 20px; } +.sign-up-message { + padding: 25px 30px 25px 30px; + text-align: justify; + font-size: 18px; + line-height: 30px; +} +.sign-up-message a { + font-size: 18px; + color: #1e94cc !important; +} + @media (max-width: 1199px) { ul.banner-social-buttons { float: left; From 707d8e737069c91aa3e7463cbbb0c118f064cfdc Mon Sep 17 00:00:00 2001 From: "M.Ravi" Date: Sun, 11 Jun 2017 05:14:20 +0530 Subject: [PATCH 4/8] Added condition to hosting form to show message for account that have not yet been validated after account creation --- hosting/forms.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hosting/forms.py b/hosting/forms.py index 1c7f7e88..d9a3b985 100644 --- a/hosting/forms.py +++ b/hosting/forms.py @@ -24,6 +24,8 @@ class HostingUserLoginForm(forms.Form): is_auth = authenticate(email=email, password=password) if not is_auth: raise forms.ValidationError("Your username and/or password were incorrect.") + elif is_auth.validated == 0: + raise forms.ValidationError(_("Your account is not activated yet.")) return self.cleaned_data def clean_email(self): From ce11524fbaf8eba6a175054cf0553234ff24e82b Mon Sep 17 00:00:00 2001 From: "M.Ravi" Date: Sun, 11 Jun 2017 05:15:48 +0530 Subject: [PATCH 5/8] Added signup-validate and validate endpoints to hosting's urls --- hosting/urls.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/hosting/urls.py b/hosting/urls.py index 959eedf0..495ac312 100644 --- a/hosting/urls.py +++ b/hosting/urls.py @@ -1,7 +1,7 @@ from django.conf.urls import url from .views import DjangoHostingView, RailsHostingView, PaymentVMView,\ - NodeJSHostingView, LoginView, SignupView, IndexView, \ + NodeJSHostingView, LoginView, SignupView, SignupValidateView, SignupValidatedView, IndexView, \ OrdersHostingListView, OrdersHostingDetailView, VirtualMachinesPlanListView,\ VirtualMachineView, OrdersHostingDeleteView, NotificationsView, \ MarkAsReadNotificationView, PasswordResetView, PasswordResetConfirmView, HostingPricingView,\ @@ -35,9 +35,11 @@ urlpatterns = [ name='read_notification'), url(r'login/?$', LoginView.as_view(), name='login'), url(r'signup/?$', SignupView.as_view(), name='signup'), + url(r'signup-validate/?$', SignupValidateView.as_view(), name='signup-validate'), url(r'reset-password/?$', PasswordResetView.as_view(), name='reset_password'), url(r'reset-password-confirm/(?P[0-9A-Za-z]+)-(?P.+)/$', PasswordResetConfirmView.as_view(), name='reset_password_confirm'), url(r'^logout/?$', 'django.contrib.auth.views.logout', - {'next_page': '/hosting/login?logged_out=true'}, name='logout') + {'next_page': '/hosting/login?logged_out=true'}, name='logout'), + url(r'^validate/(?P.*)/$', SignupValidatedView.as_view(), name='validate') ] From c989017a8f349ec4b2369bd8a9ac2b478a71d751 Mon Sep 17 00:00:00 2001 From: "M.Ravi" Date: Sun, 11 Jun 2017 05:18:06 +0530 Subject: [PATCH 6/8] Added SignupValidateView and SignupValidatedView classes to handle respective views --- hosting/views.py | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/hosting/views.py b/hosting/views.py index 7e15ac2a..b23d286b 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -18,7 +18,7 @@ from guardian.mixins import PermissionRequiredMixin from stored_messages.settings import stored_messages_settings from stored_messages.models import Message from stored_messages.api import mark_read - +from django.utils.safestring import mark_safe from membership.models import CustomUser, StripeCustomer from utils.stripe_utils import StripeUtils @@ -32,6 +32,7 @@ from .mixins import ProcessVMSelectionMixin from opennebula_api.models import OpenNebulaManager from opennebula_api.serializers import VirtualMachineSerializer,\ VirtualMachineTemplateSerializer +from django.utils.translation import ugettext_lazy as _ from oca.exceptions import OpenNebulaException @@ -199,12 +200,39 @@ class SignupView(CreateView): name = form.cleaned_data.get('name') email = form.cleaned_data.get('email') password = form.cleaned_data.get('password') + this_base_url = "{0}://{1}".format(self.request.scheme, self.request.get_host()) + CustomUser.register(name, password, email, app='dcl', base_url=this_base_url) - CustomUser.register(name, password, email) - auth_user = authenticate(email=email, password=password) - login(self.request, auth_user) + return HttpResponseRedirect(reverse_lazy('hosting:signup-validate')) - return HttpResponseRedirect(self.get_success_url()) +class SignupValidateView(TemplateView): + template_name = "hosting/signup_validate.html" + + def get_context_data(self, **kwargs): + context = super(SignupValidateView, self).get_context_data(**kwargs) + login_url = reverse('hosting:login') + message= _("Thank you for signing up. We have sent an email to you. Please follow the instructions in it to activate your account. Once activated, you can login using ") + 'login' + section_title='Sign up' + context['message'] = mark_safe(message) + context['section_title'] = section_title + return context + +class SignupValidatedView(SignupValidateView): + template_name = "hosting/signup_validate.html" + + def get_context_data(self, **kwargs): + context = super(SignupValidateView, self).get_context_data(**kwargs) + validated = CustomUser.validate_url(self.kwargs['validate_slug']) + login_url = reverse('hosting:login') + if validated: + message= _("Your account has been activated. You can now ") + 'login' + section_title=_('Account activation') + else: + message= _("Sorry. Your request is invalid.") + 'login' + section_title=_('Account activation') + context['message'] = mark_safe(message) + context['section_title'] = section_title + return context class PasswordResetView(PasswordResetViewMixin): From 2ec2b6980a2cfbecffde2ee519e68e16aeb0f4ac Mon Sep 17 00:00:00 2001 From: "M.Ravi" Date: Sun, 11 Jun 2017 05:19:56 +0530 Subject: [PATCH 7/8] Updated the CustomUser.register method so that we can handle register differently for digitalglarus and dcl --- membership/models.py | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/membership/models.py b/membership/models.py index c200b960..ecb55e88 100644 --- a/membership/models.py +++ b/membership/models.py @@ -1,8 +1,4 @@ from datetime import datetime - - - - from django.db import models from django.utils.translation import ugettext_lazy as _ from django.contrib.auth.models import User, AbstractBaseUser, BaseUserManager, AbstractUser, PermissionsMixin @@ -13,6 +9,8 @@ from django.contrib.sites.models import Site from utils.stripe_utils import StripeUtils from utils.mailer import DigitalGlarusRegistrationMailer +from django.core.urlresolvers import reverse +from utils.mailer import BaseEmail REGISTRATION_MESSAGE = {'subject': "Validation mail", 'message': 'Please validate Your account under this link http://localhost:8000/en-us/digitalglarus/login/validate/{}', @@ -75,13 +73,27 @@ class CustomUser(AbstractBaseUser, PermissionsMixin): REQUIRED_FIELDS = ['name', 'password'] @classmethod - def register(cls, name, password, email): + def register(cls, name, password, email, app='digital_glarus', base_url=None): user = cls.objects.filter(email=email).first() if not user: user = cls.objects.create_user(name=name, email=email, password=password) if user: - dg = DigitalGlarusRegistrationMailer(user.validation_slug) - dg.send_mail(to=user.email) + if app == 'digital_glarus': + dg = DigitalGlarusRegistrationMailer(user.validation_slug) + dg.send_mail(to=user.email) + elif app == 'dcl': + user.is_active = False + email_data = { + 'subject': _('Activate your datacenterlight account'), + 'from_address': '(datacenterlight) datacenterlight Support ', + '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 From 8dfcca82641945c65322c709637ddfd1496f8852 Mon Sep 17 00:00:00 2001 From: Pcoder Date: Fri, 16 Jun 2017 00:47:09 +0530 Subject: [PATCH 8/8] Fixed name for dcl --- membership/models.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/membership/models.py b/membership/models.py index ecb55e88..8bd9feec 100644 --- a/membership/models.py +++ b/membership/models.py @@ -84,8 +84,8 @@ class CustomUser(AbstractBaseUser, PermissionsMixin): elif app == 'dcl': user.is_active = False email_data = { - 'subject': _('Activate your datacenterlight account'), - 'from_address': '(datacenterlight) datacenterlight Support ', + 'subject': _('Activate your Data Center Light account'), + 'from_address': '(Data Center Light) Data Center Light Support ', 'to': user.email, 'context': {'base_url' : base_url, 'activation_link' : reverse('hosting:validate', kwargs={'validate_slug': user.validation_slug})},