def validate(self, attrs):
email_or_username = attrs.get('email_or_username')
password = attrs.get('password')
if email_or_username and password:
# Check if user sent email
if validateEmail(email_or_username):
user_request = get_object_or_404(
User,
email=email_or_username,
)
email_or_username = user_request.username
user = authenticate(username=email_or_username, password=password)
if user:
if not user.is_active:
msg = _('User account is disabled.')
raise ValidationError(msg)
else:
msg = _('Unable to log in with provided credentials.')
raise ValidationError(msg)
else:
msg = _('Must include "email or username" and "password"')
raise ValidationError(msg)
attrs['user'] = user
return attrs
# class ProfileSerializer(serializers.ModelSerializer):
#
# class Meta:
# model = UserProfile
# exclude = ('user', 'id', 'organization')
#
评论列表
文章目录