Пример #1
0
    def post(self, request, *args, **kwargs):
        """
        Would help to validate user and login the user.
        """
        model = kwargs['model']

        form = self.form_class(request.POST)

        if form.is_valid():
            email = form.cleaned_data['email']
            password = form.cleaned_data['password']
            user = authenticate(model, email=email, password=password)

            if user is not None:
                login(request, user)
                request.session['_id'] = user.pk

                # if model is publisher model.
                if model == Publisher:
                    request.session['user_type'] = constants.USER_PUBLISHER
                    return HttpResponseRedirect(self.get_success_url())
                elif model == Sponsor:
                    # if model is sponsor model.
                    request.session['user_type'] = constants.USER_SPONSOR
                    return HttpResponseRedirect(self.get_success_url())
            messages.error(request, "Wrong username and Password combination.")
            return self.form_invalid(form)
        else:
            return self.form_invalid(form)
Пример #2
0
    def clean_old_password(self):
        password = self.cleaned_data['old_password']
        user = authenticate(self.model, username=self.username, password=password)

        if user is None:
            raise forms.ValidationError(_("Old password does match for the user."))  
        return self.cleaned_data