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
+
+
+
+ + + 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): diff --git a/hosting/static/hosting/css/landing-page.css b/hosting/static/hosting/css/landing-page.css index dd25715f..d7d72ee2 100644 --- a/hosting/static/hosting/css/landing-page.css +++ b/hosting/static/hosting/css/landing-page.css @@ -318,6 +318,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; 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 %} 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') ] diff --git a/hosting/views.py b/hosting/views.py index e0b5daec..87d5bad0 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): diff --git a/membership/models.py b/membership/models.py index c200b960..8bd9feec 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 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})}, + 'template_name': 'user_activation', + 'template_path': 'datacenterlight/emails/' + } + email = BaseEmail(**email_data) + email.send() return user else: return None