Can't login after changing base user model to custom one

I have recently changed my user model to a custom one and can't login to both admin (with superusers) and website (wit normal users) anymore. I use the email field for authentication. I guess there's something I didn't consider but since there are no errors I dont know where to search.

Note: When I try to login (admin or website) the login form just refreshes with empty inputs, so I guess the form is not valid? If so, why?


from django.core.mail import send_mail
from django.db import models
from django.contrib.auth.models import User
from django.db.models.signals import post_save
from django.dispatch import receiver
from django.contrib.auth.models import AbstractBaseUser
from django.contrib.auth.models import PermissionsMixin
from django.contrib.auth.models import BaseUserManager

class UserProfileManager(BaseUserManager):
    """ Manager for user profiles """

    def create_user(self, email, name, password=None):
        """ Create a new user profile """
        if not email:
            raise ValueError('User must have an email address')

        email = self.normalize_email(email)
        user = self.model(email=email, name=name)


        return user

    def create_superuser(self, email, name, password):
        """ Create a new superuser profile """
        user = self.create_user(email, name, password)
        user.is_superuser = True
        user.is_staff = True

        return user

class UserProfile(AbstractBaseUser, PermissionsMixin):
    """ Database model for users in the system """
    email = models.EmailField(max_length=255, unique=True)
    name = models.CharField(max_length=255)

    is_staff = models.BooleanField(default=False)
    is_superuser = models.BooleanField(default=False)
    is_active = models.BooleanField(default=False)
    email_confirmed = models.BooleanField(default=False)

    objects = UserProfileManager()

    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = ['name']

    def email_user(self, subject, message, from_email=None, **kwargs):
        """Copied from original class"""
        send_mail(subject, message, from_email, [], **kwargs)

    def __str__(self):

@receiver(post_save, sender=User)
def update_user_profile(sender, instance, created, **kwargs):
    if created:

class UserLoginForm(AuthenticationForm):
    def __init__(self, *args, **kwargs):
        super(UserLoginForm, self).__init__(*args, **kwargs)

    email = forms.EmailField(required=True, widget=forms.EmailInput(attrs={
        'class': tailwind_class
    password = forms.CharField(widget=forms.PasswordInput(
        attrs={'class': tailwind_class}))

    path('login/', views.LoginView.as_view(template_name='user/login.html', authentication_form=UserLoginForm), name="login"),

Back to Top