Added SignupValidateView and SignupValidatedView classes to handle respective views

This commit is contained in:
M.Ravi 2017-06-11 05:18:06 +05:30
parent ce11524fba
commit c989017a8f

View file

@ -18,7 +18,7 @@ from guardian.mixins import PermissionRequiredMixin
from stored_messages.settings import stored_messages_settings from stored_messages.settings import stored_messages_settings
from stored_messages.models import Message from stored_messages.models import Message
from stored_messages.api import mark_read from stored_messages.api import mark_read
from django.utils.safestring import mark_safe
from membership.models import CustomUser, StripeCustomer from membership.models import CustomUser, StripeCustomer
from utils.stripe_utils import StripeUtils from utils.stripe_utils import StripeUtils
@ -32,6 +32,7 @@ from .mixins import ProcessVMSelectionMixin
from opennebula_api.models import OpenNebulaManager from opennebula_api.models import OpenNebulaManager
from opennebula_api.serializers import VirtualMachineSerializer,\ from opennebula_api.serializers import VirtualMachineSerializer,\
VirtualMachineTemplateSerializer VirtualMachineTemplateSerializer
from django.utils.translation import ugettext_lazy as _
from oca.exceptions import OpenNebulaException from oca.exceptions import OpenNebulaException
@ -199,12 +200,39 @@ class SignupView(CreateView):
name = form.cleaned_data.get('name') name = form.cleaned_data.get('name')
email = form.cleaned_data.get('email') email = form.cleaned_data.get('email')
password = form.cleaned_data.get('password') 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) return HttpResponseRedirect(reverse_lazy('hosting:signup-validate'))
auth_user = authenticate(email=email, password=password)
login(self.request, auth_user)
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 ") + '<a href="' + login_url +'">login</a>'
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 ") + '<a href="' + login_url +'">login</a>'
section_title=_('Account activation')
else:
message= _("Sorry. Your request is invalid.") + '<a href="' + login_url +'">login</a>'
section_title=_('Account activation')
context['message'] = mark_safe(message)
context['section_title'] = section_title
return context
class PasswordResetView(PasswordResetViewMixin): class PasswordResetView(PasswordResetViewMixin):