From da6a0c286dcb7cebaf869ffdfe483bfb46f67d21 Mon Sep 17 00:00:00 2001 From: Bai Date: Mon, 20 Jan 2020 11:27:34 +0800 Subject: [PATCH] =?UTF-8?q?[Update]=20=E4=BF=AE=E5=A4=8D=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E9=A1=B5=E9=9D=A2=E4=BC=9A=E6=B8=85=E7=A9=BA?= =?UTF-8?q?=E7=94=A8=E6=88=B7public=5Fkey=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/users/serializers/user.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/apps/users/serializers/user.py b/apps/users/serializers/user.py index 2363c39ed..da9b725ec 100644 --- a/apps/users/serializers/user.py +++ b/apps/users/serializers/user.py @@ -74,8 +74,17 @@ class UserSerializer(BulkSerializerMixin, serializers.ModelSerializer): attrs['password_raw'] = password return attrs + @staticmethod + def clean_auth_fields(attrs): + for field in ('password', 'public_key'): + value = attrs.get(field) + if not value: + attrs.pop(field, None) + return attrs + def validate(self, attrs): attrs = self.change_password_to_raw(attrs) + attrs = self.clean_auth_fields(attrs) return attrs