2

I have a custom user model which was working without error, later I add field for user image then I can do registration but unable to login.

I think there is error in the save() method.

I don't accept user image in registration page, but there is template for loggedin user to add later

from django.db import models
from django.contrib.auth.models import AbstractUser
from PIL import Image

class User(AbstractUser):
    email = models.EmailField(verbose_name='email' ,max_length=223,unique=True)
    photo = models.ImageField(upload_to='prof_pic', blank=True,null=True)
    phone=models.CharField(null=True,max_length=11)
    REQUIRED_FIELDS = [ 'email','phone']



    def save(self,*args, **kwargs):
        super().save()
        if self.photo:
            pic = Image.open(self.photo.path)
            if pic.height > 300 or pic.width > 300:
                output_size = (300, 300)
                pic.thumbnail(output_size)
                pic.save(self.photo.path)
            super(User, self).save(*args, **kwargs)        

ERROR WHEN LOGGING IN

Please enter a correct username and password. Note that both fields may be case-sensitive.
Anoop K George
  • 1,605
  • 12
  • 40

1 Answers1

0

https://stackoverflow.com/a/8845337/10515390 check the answer on this link.

I have added authentication back-end.

Akash Pagar
  • 637
  • 8
  • 22
Anoop K George
  • 1,605
  • 12
  • 40