From 2276533185fa7ebf5998222042bf1e021580d91d Mon Sep 17 00:00:00 2001 From: PCoder Date: Sat, 2 Sep 2017 16:36:20 +0530 Subject: [PATCH] Reformatted utils/views.py and added a condition to DCL_TEXT in passoword reset email --- utils/views.py | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/utils/views.py b/utils/views.py index 8aea6d5b..8198a01c 100644 --- a/utils/views.py +++ b/utils/views.py @@ -1,16 +1,16 @@ -from django.views.generic import FormView, CreateView -from django.utils.http import urlsafe_base64_encode, urlsafe_base64_decode from django.conf import settings from django.contrib import messages -from django.contrib.auth.tokens import default_token_generator -from django.utils.encoding import force_bytes -from django.http import HttpResponseRedirect from django.contrib.auth import authenticate, login +from django.contrib.auth.tokens import default_token_generator +from django.http import HttpResponseRedirect +from django.utils.encoding import force_bytes +from django.utils.http import urlsafe_base64_encode, urlsafe_base64_decode from django.utils.translation import ugettext_lazy as _ -from membership.models import CustomUser +from django.views.generic import FormView, CreateView -from .mailer import BaseEmail +from membership.models import CustomUser from .forms import SetPasswordForm +from .mailer import BaseEmail class SignupViewMixin(CreateView): @@ -18,8 +18,8 @@ class SignupViewMixin(CreateView): success_url = None def get_success_url(self): - - next_url = self.request.POST.get('next') if self.request.POST.get('next')\ + next_url = self.request.POST.get('next') if self.request.POST.get( + 'next') \ else self.success_url return next_url @@ -66,7 +66,8 @@ class LoginViewMixin(FormView): class PasswordResetViewMixin(FormView): # template_name = 'hosting/reset_password.html' # form_class = PasswordResetRequestForm - success_message = _("The link to reset your email has been sent to your email") + success_message = _( + "The link to reset your email has been sent to your email") site = '' def test_generate_email_context(self, user): @@ -74,8 +75,9 @@ class PasswordResetViewMixin(FormView): 'user': user, 'token': default_token_generator.make_token(user), 'uid': urlsafe_base64_encode(force_bytes(user.pk)), - 'site_name': 'ungleich', - 'base_url': "{0}://{1}".format(self.request.scheme, self.request.get_host()) + 'site_name': 'ungleich' if self.site != 'dcl' else settings.DCL_TEXT, + 'base_url': "{0}://{1}".format(self.request.scheme, + self.request.get_host()) } return context @@ -83,7 +85,8 @@ class PasswordResetViewMixin(FormView): def form_valid(self, form): email = form.cleaned_data.get('email') user = CustomUser.objects.get(email=email) - messages.add_message(self.request, messages.SUCCESS, self.success_message) + messages.add_message(self.request, messages.SUCCESS, + self.success_message) context = self.test_generate_email_context(user) email_data = { 'subject': _('Password Reset'), @@ -103,6 +106,7 @@ class PasswordResetViewMixin(FormView): class PasswordResetConfirmViewMixin(FormView): # template_name = 'hosting/confirm_reset_password.html' form_class = SetPasswordForm + # success_url = reverse_lazy('hosting:login') def post(self, request, uidb64=None, token=None, *arg, **kwargs): @@ -114,7 +118,8 @@ class PasswordResetConfirmViewMixin(FormView): form = self.form_class(request.POST) - if user is not None and default_token_generator.check_token(user, token): + if user is not None and default_token_generator.check_token(user, + token): if form.is_valid(): new_password = form.cleaned_data['new_password2'] user.set_password(new_password) @@ -122,11 +127,13 @@ class PasswordResetConfirmViewMixin(FormView): messages.success(request, 'Password has been reset.') return self.form_valid(form) else: - messages.error(request, 'Password reset has not been successful.') + messages.error(request, + 'Password reset has not been successful.') form.add_error(None, 'Password reset has not been successful.') return self.form_invalid(form) else: - messages.error(request, 'The reset password link is no longer valid.') + messages.error(request, + 'The reset password link is no longer valid.') form.add_error(None, 'The reset password link is no longer valid.') return self.form_invalid(form)