From c989017a8f349ec4b2369bd8a9ac2b478a71d751 Mon Sep 17 00:00:00 2001 From: "M.Ravi" Date: Sun, 11 Jun 2017 05:18:06 +0530 Subject: [PATCH] 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):