def validate(self, data):
errors = dict()
if data.get('password') or data.get('current_password'):
current_password = data.pop('current_password', '')
password = data.get('password', '')
try:
validate_password(password=password)
except ValidationError as e:
errors['password'] = list(e.messages)
if not authenticate(email=self.context['request'].user.email, password=current_password, channel=self.context["request"].channel):
errors['current_password'] = ["Invalid password."]
if errors:
raise serializers.ValidationError(errors)
return super(UserCreateSerializer, self).validate(data)
user.py 文件源码
python
阅读 34
收藏 0
点赞 0
评论 0
评论列表
文章目录