From 7f9644dbac6677b1a0b206c681f510cf7e79a23d Mon Sep 17 00:00:00 2001 From: Bai Date: Sun, 19 Jan 2020 12:13:42 +0800 Subject: [PATCH 1/2] =?UTF-8?q?[Update]=20=E4=BF=AE=E6=94=B9=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E7=94=A8=E6=88=B7=E7=99=BB=E5=BD=95=E7=9A=84ip?= =?UTF-8?q?=E5=92=8Ctype?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/audits/signals_handler.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/apps/audits/signals_handler.py b/apps/audits/signals_handler.py index 9579ca6e5..dab56fa5c 100644 --- a/apps/audits/signals_handler.py +++ b/apps/audits/signals_handler.py @@ -111,12 +111,10 @@ def on_audits_log_create(sender, instance=None, **kwargs): def generate_data(username, request): user_agent = request.META.get('HTTP_USER_AGENT', '') - + login_ip = get_request_ip(request) or '0.0.0.0' if isinstance(request, Request): - login_ip = request.data.get('remote_addr', '0.0.0.0') - login_type = request.data.get('login_type', '') + login_type = request.META.get('HTTP_X_JMS_LOGIN_TYPE', '') else: - login_ip = get_request_ip(request) or '0.0.0.0' login_type = 'W' data = { From da6a0c286dcb7cebaf869ffdfe483bfb46f67d21 Mon Sep 17 00:00:00 2001 From: Bai Date: Mon, 20 Jan 2020 11:27:34 +0800 Subject: [PATCH 2/2] =?UTF-8?q?[Update]=20=E4=BF=AE=E5=A4=8D=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E6=9B=B4=E6=96=B0=E9=A1=B5=E9=9D=A2=E4=BC=9A=E6=B8=85?= =?UTF-8?q?=E7=A9=BA=E7=94=A8=E6=88=B7public=5Fkey=E7=9A=84=E9=97=AE?= =?UTF-8?q?=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