Rest-auth: Exlamation mark comes before password
Pranay9752 opened this issue · 2 comments
Pranay9752 commented
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
BarnabasSzabolcs commented
Hi,
this repo is not maintained anymore, so the development moved to dj-rest-auth. (reference: #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
sanjaysupanch commented
- 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
`