Saturday, March 28, 2020

Re: email": [ "Enter a valid email address." ]

Hi Friend,

I added domains to the source code of EmailValidator (last line) and it the error is still there. Do you know what I am doing wrong? 

class UserSerializer(serializers.ModelSerializer):

class Meta:
model = User
fields = ('email', 'password')

http -f POST http://127.0.0.1:8000/reg email="l55@gmail.com", password='pw'


{

    "email": [

        "Enter a valid email address."

    ]

}


@deconstructible
class EmailValidator:
message = _('Enter a valid email address. Not valid')
code = 'invalid'
user_regex = _lazy_re_compile(
r"(^[-!#$%&'*+/=?^_`{}|~0-9A-Z]+(\.[-!#$%&'*+/=?^_`{}|~0-9A-Z]+)*\Z" # dot-atom
r'|^"([\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\001-\011\013\014\016-\177])*"\Z)', # quoted-string
re.IGNORECASE)
domain_regex = _lazy_re_compile(
# max length for domain name labels is 63 characters per RFC 1034
r'((?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+)(?:[A-Z0-9-]{2,63}(?<!-))\Z',
re.IGNORECASE)
literal_regex = _lazy_re_compile(
# literal form, ipv4 or ipv6 address (SMTP 4.1.3)
r'\[([A-f0-9:\.]+)\]\Z',
re.IGNORECASE)
domain_whitelist = ['localhost', 'gmail', 'gmail.com', '@gmail.com']

Thanks Django Community 

On Fri, Mar 27, 2020 at 9:24 AM Integr@te System <datacentralize@gmail.com> wrote:
Hi Freind,

Plz look back the doc in Emailvalidator and decive your use case:


On Fri, Mar 27, 2020, 18:19 Ben Magnelli <devyen936@gmail.com> wrote:
 AUTH_USER_MODEL = 'users.User

Yep, I have that in settings.py

In serializers.py if I change EmailField to CharField, it does serialize. However, then it's not really checking if it's a email. And EmailField should work.
class User(AbstractBaseUser, PermissionsMixin):
email = models.CharField(max_length=256, unique=True)
Thank you DjangoUsers

On Mar 27, 2020, at 4:49 AM, Motaz Hejaze <trapperx.1@gmail.com> wrote:


I think django doesnt recognize your custom user model ..

Did you your app to installed app and put AUTH_USER_MODEL = 'myapp.MyUser'
in settings.py ?

On Fri, 27 Mar 2020, 3:33 am devyen, <devyen936@gmail.com> wrote:
Hi 

Do know how to whitelist an email domain name? It seems odd that I would have to go though an white list all of the main email domains (gmail, protonmail, live, yahoo etc.)

Ive been unable to figure it out on my own
 
Thanks,



On Sat, Mar 21, 2020 at 4:45 AM Integr@te System <datacentralize@gmail.com> wrote:
Hi Freind,

Try to set whitelist for your specific domain testing or refer doc for your case. 


On Sat, Mar 21, 2020, 03:47 devyen <devyen936@gmail.com> wrote:
Hi,

I am tying to use the EmailField in my AbstractBaseUser Class see below. However the serializer does not recognize any emails as valid (I tested with this one, which is clearly valid) 

Can you help me?

Thank you so much!


models.py
class User(AbstractBaseUser, PermissionsMixin):
email = models.EmailField(max_length=256, unique=True)
first_name = models.TextField(verbose_name="First Name", blank=True)
last_name = models.TextField(verbose_name="Last Name", blank=True)
user_id = models.TextField(unique=True)
data = JSONField(default=default_data, name="device_data")
is_staff = models.BooleanField(default=False)
is_active = models.BooleanField(default=True)
date_joined = models.DateTimeField(default=timezone.now)

objects = UserManager()

USERNAME_FIELD = 'email'

def __str__(self):
return self.email

def get_first_name(self):
return self.first_name

def get_last_name(self):
return self.last_name

def get_email(self):
return self.email

def __unicode__(self):
return self.email, self.user_id

def get_user_id(self):
return self.user_id
serializers.py

from rest_framework import serializers
from .models import User


class UserSerializer(serializers.ModelSerializer):
class Meta:
model = User
fields = ['email', 'password']

part of views.py

class UserRegistration(APIView):
def post(self, request):
serializer = UserSerializer(data=request.data)
if serializer.is_valid():
print('valid')
user_object = []
email = serializer.validated_data['email']
password = serializer.validated_data['password']
if "first_name" in serializer.validated_data:
first_name = serializer.validated_data['first_name']
user_object.append(first_name)
else:
pass
if "last_name" in serializer.validated_data:
last_name = serializer.validated_data['last_name']
user_object.append(last_name)
else:
pass

# serializer.save()
return Response(user_object, status=status.HTTP_201_CREATED)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

I send this:

http -f POST http://127.0.0.1:8000/reg email='k@k.com', password='pw'


to receive this error:

{

    "email": [

        "Enter a valid email address."

    ]

}

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/bc92176b-7eb2-4e2a-a8a0-215eef7392c7%40googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/NHUy2I3ZVDg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAP5HUWrxXTmMovbmz2KCUG6%3DRMy10fNW6A-hkQdkbNWqZxYGNw%40mail.gmail.com.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2B%3DqY%3DPvkQe%2B6EdeMRZaiJ%3DnYKn%3Dd1b_JivqL4c4%3Dacr28D74Q%40mail.gmail.com.

--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/NHUy2I3ZVDg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAHV4E-d4s0OnS9%2Bd7%3D4Be7NG4Xa5v%2BNcx5r7%3DpiwV3KjcOJQGw%40mail.gmail.com.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/51C89967-0014-40E0-9023-A67E0390518F%40gmail.com.

--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/NHUy2I3ZVDg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAP5HUWrQG8WG%3DMfKAiU4-X6Qv%3DE52m1uSi%2BoGv1Jnfwc2R-eig%40mail.gmail.com.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2B%3DqY%3DMqTqNFMy5HYMzRrnoud7TxQ6aF%3DhDYgMe4akgHYqwLyA%40mail.gmail.com.

No comments:

Post a Comment