Source code for shoop.front.apps.registration.views
# -*- coding: utf-8 -*-
# This file is part of Shoop.
#
# Copyright (c) 2012-2016, Shoop Ltd. All rights reserved.
#
# This source code is licensed under the AGPLv3 license found in the
# LICENSE file in the root directory of this source tree.
from django.conf import settings
from django.contrib import messages
from django.contrib.auth import REDIRECT_FIELD_NAME
from django.shortcuts import redirect
from django.utils.http import is_safe_url
from django.utils.translation import ugettext_lazy as _
from django.views.generic import View
from registration.backends.default import views as default_views
from registration.backends.simple import views as simple_views
from shoop.front.template_helpers import urls
[docs]def activation_complete(request):
messages.success(request, _("Activation successful!"))
if urls.has_url('shoop:customer_edit'):
return redirect('shoop:customer_edit')
else:
return redirect(settings.LOGIN_REDIRECT_URL)
[docs]def registration_complete(request):
messages.success(request, _("Registration complete. Please follow the instructions sent to your email address."))
return redirect(settings.LOGIN_REDIRECT_URL)
[docs]class RegistrationViewMixin(object):
template_name = "shoop/registration/register.jinja"
[docs] def get_success_url(self, *args, **kwargs):
url = self.request.REQUEST.get(REDIRECT_FIELD_NAME)
if url and is_safe_url(url, self.request.get_host()):
return url
return ('shoop:registration_complete', (), {})
[docs]class RegistrationNoActivationView(RegistrationViewMixin, simple_views.RegistrationView):
pass
[docs]class RegistrationWithActivationView(RegistrationViewMixin, default_views.RegistrationView):
pass
[docs]class RegistrationView(View):
[docs] def dispatch(self, request, *args, **kwargs):
if settings.SHOOP_REGISTRATION_REQUIRES_ACTIVATION:
view_class = RegistrationWithActivationView
else:
view_class = RegistrationNoActivationView
return view_class.as_view()(request, *args, **kwargs)
[docs]class ActivationView(default_views.ActivationView):
template_name = "shoop/registration/activation_failed.jinja"
[docs] def get_success_url(self, *args, **kwargs):
return ('shoop:registration_activation_complete', (), {})