mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-11-26 16:44:54 +00:00
forgot, reset and change password
This commit is contained in:
@ -36,8 +36,34 @@ class ResetPasswordSerializer(serializers.Serializer):
|
||||
user_details.set_password(password)
|
||||
user_details.save()
|
||||
return {'password':password}
|
||||
return user_opt_details
|
||||
return user_opt_details
|
||||
return ''
|
||||
|
||||
class ChangePasswordSerializer(serializers.Serializer):
|
||||
"""Update Password after verification"""
|
||||
current_password = serializers.CharField(max_length=100)
|
||||
new_password = serializers.CharField(required=True)
|
||||
class Meta(object):
|
||||
"""Meta info"""
|
||||
model = User
|
||||
|
||||
def validate_current_password(self, value):
|
||||
user = self.context
|
||||
if self.context.password not in ('', None):
|
||||
if user.check_password(value):
|
||||
return value
|
||||
raise serializers.ValidationError({"error":"Invalid Current password"})
|
||||
def create(self, validated_data):
|
||||
new_password = validated_data.pop('new_password')
|
||||
user_details = User.objects.filter(email=self.context).last()
|
||||
print("user_details==>", user_details)
|
||||
if user_details:
|
||||
print("333333333==>",user_details.password)
|
||||
user_details.set_password(new_password)
|
||||
user_details.save()
|
||||
return {'password':new_password}
|
||||
return user_details
|
||||
return ''
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user