Cannot login user and admin user to the main website


Building a django project and successfully done the registration, login, logout and activate views, the registration is working because a user get a link sent to their email after they signup but I’m having errors saying invalid credentials when I try to login with that created account also same with trying to login with the admin password and email address, can only login to the admin panel. Here is the codes.

from django.contrib.auth.models import AbstractBaseUser, BaseUserManager

class MyAccountManager(BaseUserManager):
    def create_user(self, first_name, last_name, username, email, password=False):
        if not email:
            raise ValueError("Please user must have a email address")
        if not username:
            raise ValueError("Please User must have a username")
        user = self.model(
            email = self.normalize_email(email),
            username= username,
            first_name = first_name,
            last_name = last_name,
        return user
    def create_superuser(self,first_name, last_name, email, username, password):
        user = self.create_user(
            email = self.normalize_email(email),
            username= username,
            first_name = first_name,
            last_name = last_name,
        user.is_admin = True
        user.is_active = True
        user.is_staff = True
        user.is_superadmin = True
        return user
class Account(AbstractBaseUser):
    first_name = models.CharField(max_length=50)
    last_name = models.CharField(max_length=50)
    username = models.CharField(max_length=50, unique=True)
    email = models.EmailField(max_length=100, unique=True)
    phone_number =  models.CharField(max_length=50)
    #required fields
    date_joined = models.DateTimeField(auto_now_add=True)
    last_login = models.DateTimeField(auto_now_add=True)
    is_admin = models.BooleanField(default=False)
    is_active =  models.BooleanField(default=False)
    is_staff = models.BooleanField(default=False)
    is_superadmin = models.BooleanField(default=False)
    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = ['username', 'first_name', 'last_name']
    objects = MyAccountManager()
    def full_name(self):
        return f'{self.first_name} {self.last_name}'
    def __str__(self):
    def has_perm(self, perm, obj=None):
        return self.is_admin
    def has_module_perms(self, add_label):
        return True for register

# Create your views here.
def register(request):
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            first_name = form.cleaned_data['first_name']
            last_name = form.cleaned_data['last_name']
            phone_number = form.cleaned_data['phone_number']
            email = form.cleaned_data['email']
            password = form.cleaned_data['password']
            username = email.split('@')[0]
            user = Account.objects.create_user(first_name=first_name, last_name=last_name, email=email, username=username, password=password)
            user.phone_number = phone_number

             # Create a user profile
            profile = UserProfile()
            profile.user_id =
            profile.profile_picture = 'default/default.png'
            #user activation
            current_site = get_current_site(request)
            mail_subject = "Welcome to ECO, Please activate your account"
            message = render_to_string('ecousers/account_verification_email.html', {
                'user': user,
                'uid': urlsafe_base64_encode(force_bytes(,
                'token': default_token_generator.make_token(user),
            to_email = email
            send_email = EmailMessage(mail_subject, message, to=[to_email])
            # messages.success(request, "Account created successfully")
            return redirect('/accounts/login/?command=verification&email='+email)
        form = RegistrationForm()
    context = {
        'form': form,
    return render(request, 'ecousers/register.html', context)

login and activate views

def login(request):
    if request.method =="POST":
        email = request.POST['email']
        password = request.POST['password']

        user = auth.authenticate(email=email, password=password)

        if user is not None:
            auth.login(request, user)

            return redirect('/')

            messages.error(request, "Invalid login credentials")
            return redirect('ecousers:login')
    return render(request, 'ecousers/login.html')

def logout(request):
    messages.success(request, "You are now logged out")
    return redirect('ecousers:login')

def activate(request, uidb64, token):
        uid = urlsafe_base64_decode(uidb64).decode()
        user = Account._default_manager.get(pk=uid)
    except(TypeError, ValueError, OverflowError, Account.DoesNotExist):
        user =None
    if user is not None and default_token_generator.check_token(user, token):
        user.is_active = True
        messages.success(request, 'Congratulations!! Your account is activated')
        return redirect('ecousers:login')
        messages.error(request, 'Invalid activation link')
        return redirect('ecousers:register')

Please I can’t seem to know where the error is from, tried everything, your feedback and help will be highly appreciated

Asked By: unuefe ejovwoke



Fixed the error, on I didn’t set the auth user to the one I’m using, so I added this code on

AUTH_USER_MODEL = ‘ecousers.Account’

Answered By: unuefe ejovwoke