django-rest-auth icon indicating copy to clipboard operation
django-rest-auth copied to clipboard

Rest-auth: Exlamation mark comes before password

Open Pranay9752 opened this issue 4 years ago • 2 comments

I am using rest-auth for authentication. after registration when I try to login it show { "non_field_errors": [ "Unable to log in with provided credentials." ] } and when I saw the user on admin panel an an '!' mark comed before password for example password ='!72wlGF0RiGRraz69sveb63FUrebNkAW9xmOoL16C' please help

Pranay9752 avatar May 02 '20 17:05 Pranay9752

Hi,

this repo is not maintained anymore, so the development moved to dj-rest-auth. (reference: https://github.com/Tivix/django-rest-auth/issues/568) It may be best, if you move this PR there. (and upgrade to using dj_rest_auth)

new repo link: https://github.com/jazzband/dj-rest-auth (I'm not the upkeeper of that repo, it just makes sense for me to help you write where it brings value.)

Best, Barney

BarnabasSzabolcs avatar May 30 '20 01:05 BarnabasSzabolcs

  • Use password field is password1 = serializers.CharField(max_length=255, style={'input_type': 'password'})
  • Write this function on RegisterSerializer def validate_password1(self, password): return get_adapter().clean_password(password) #============================My Code==============================
class RegisterSerializer(serializers.Serializer):
    username = None
    email = serializers.EmailField(required=allauth_settings.EMAIL_REQUIRED)
    full_name = serializers.CharField(required=True, write_only=True)
    phone_number = serializers.CharField(required=True, write_only=True)
    password1 = serializers.CharField(max_length=255, style={'input_type': 'password'})

    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 custom_signup(self, request, user):
        user.full_name = self.validated_data.get('full_name', '')
        user.phone_number = self.validated_data.get('phone_number', '')
        user.save(update_fields=['full_name', 'phone_number'])

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

    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)
        self.custom_signup(request, user)
        setup_user_email(request, user, [])
        return user
`

sanjaysupanch avatar Jul 12 '20 21:07 sanjaysupanch