Django login fails after mail activation

Here's how a signup works:

class SignUpView(FormView):
    template_name = 'center-form.html'
    form_class = SignUpForm

    def form_valid(self, form):
        if form.is_valid():
            user = User.objects.create_user(
                first_name=form.cleaned_data['first_name'],
                last_name=form.cleaned_data['last_name'],
                username=form.cleaned_data['username'],
                email=form.cleaned_data['email'],
                password=form.cleaned_data['password1'],
                is_active=False,
            )
            activation_code = uuid.uuid4().hex
            Activation.objects.create(code=activation_code, user=user)
            activation_url = self.request.build_absolute_uri(
                reverse('activate', kwargs={'code': activation_code})
            )
            send_mail(
                'Activate account',
                f'To activate your account, please follow the link below\n{activation_url}',
                'Django',
                [form.cleaned_data['email']],
                fail_silently=False,
            )
            messages.success(
                self.request,
                'Please check your email for a message with the activation code.',
            )
        return redirect('index')

I eventually get a mail which contains some activation code. By clicking the link, I get a message indicating success as a result of:

class ActivationView(View):
    @staticmethod
    def get(request, code):
        activation = get_object_or_404(Activation, code=code)
        activation.user.is_active = True
        login(request, activation.user)
        activation.user.save()
        activation.delete()
        messages.success(request, 'You have successfully activated your account')
        return redirect('index')

However, when I try to sign in using the email and password used earlier, I get an error in the form:

 Please enter a correct username and password. Note that both fields may be case-sensitive.

The form is AuthenticationForm and here's the view:

class SignInView(LoginView):
    template_name = 'center-form.html'

    def get_context_data(self, **kwargs):
        data = super().get_context_data(**kwargs)
        data.update({'form_title': 'Sign in'})
        return data
Back to Top