RegisterSerializer doesn't recognize data from rest-auth/registration API, except for email data.

236 views
Skip to first unread message

kanda....@kaigomedia.co.jp

unread,
Apr 19, 2019, 8:04:50 AM4/19/19
to Django REST framework
Hi, I hope any of you can help me out.
I am trying build user registrations by using rest-auth/registration API.
However, after rest-auth/registration send data which has an email, a company name, a user name, and etc to ResisterSerializer, it ONLY recognizes an email data.

Here is my rest-auth/registration code.

 axios.post(`${process.env.API_ENDPOINT}rest-auth/registration/`,
     {
       company: this.company,
       username: this.username,
       email: this.email,
       password1: this.password1,
       password2: this.password2
     }).then(res => {
         this.$router.push('/login')
       })
       .catch(function(error){
         this.nonFieldErrors = error.response.data
       })
       .finally(() => this.loading = false)

and this is ResisterSerializer code below.

class RegisterSerializer(serializers.Serializer):
   company = serializers.CharField(required=True)
   username = serializers.CharField(required=True)
   email = serializers.EmailField(required=allauth_settings.EMAIL_REQUIRED)
   password1 = serializers.CharField(required=True)
   password2 = serializers.CharField(required=True)

   def validate_email(self, email):
       email = get_adapter().clean_email(email)
       if allauth_settings.UNIQUE_EMAIL:
           if email and email_address_exists(email):
               raise serializers.ValidationError(
                   _("A user is already registered with this e-mail address."))
       return email

   def validate_password1(self, password):
       return get_adapter().clean_password(password)

   def validate(self, data):
       if data['password1'] != data['password2']:
           raise serializers.ValidationError(
               _("The two password fields didn't match."))
       return data

   def get_cleaned_data(self):
       return {
           'company': self.validated_data.get('company', ''),
           'username': self.validated_data.get('username', ''),
           'password1': self.validated_data.get('password1', ''),
           'email': self.validated_data.get('email', ''),
       }

   def save(self, request):
       adapter = get_adapter()
       user = adapter.new_user(request)
       self.cleaned_data = self.get_cleaned_data()
       adapter.save_user(request, user, self)
       setup_user_email(request, user, [])
       user.save()
       return user

class VerifyEmailSerializer(serializers.Serializer):
   key = serializers.CharField()


Could you please give me advises.
Thank you very much.



Gonzalo Amadio

unread,
Sep 12, 2019, 8:59:29 AM9/12/19
to Django REST framework
Coould you solve this problem? What was it?
Have you debug it.

Can you give more context about the error or what you see?

--
You received this message because you are subscribed to the Google Groups "Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-rest-fram...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
--------
Gonzalo Amadio

Carl Nobile

unread,
Sep 12, 2019, 10:35:31 AM9/12/19
to django-res...@googlegroups.com
First off NEVER EVER put credentials in the body of a request. This introduces a serious security hole (bodies get logged and the creds will be in the log). Use the Authorization header and Basic auth then always use HTTPS (TLS). Authorization: Basic <credentials> See https://en.wikipedia.org/wiki/Basic_access_authentication
Also, comparing duel passwords should be compared in the client code, not the server backend, so they are not needed in the request.
If you use the header then the only values needed in the request is the email and company.

~Carl



--
-------------------------------------------------------------------------------
Carl J. Nobile (Software Engineer)
carl....@gmail.com
-------------------------------------------------------------------------------
Reply all
Reply to author
Forward
0 new messages