From 403b6fc56372b946441ae5980e625c39d5f93247 Mon Sep 17 00:00:00 2001 From: Bai Date: Thu, 4 Jun 2020 17:02:43 +0800 Subject: [PATCH] =?UTF-8?q?[Update]=20=E4=BF=AE=E6=94=B9=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E6=9B=B4=E6=96=B0Public=5Fkey=E7=9A=84=E6=9D=A1=E4=BB=B6?= =?UTF-8?q?=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/users/api/profile.py | 5 ----- apps/users/models/user.py | 7 ++++--- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/apps/users/api/profile.py b/apps/users/api/profile.py index 321ef54e1..e9631b5b7 100644 --- a/apps/users/api/profile.py +++ b/apps/users/api/profile.py @@ -83,8 +83,3 @@ class UserPublicKeyApi(generics.RetrieveUpdateAPIView): def get_object(self): return self.request.user - - def perform_update(self, serializer): - user = self.get_object() - user.public_key = serializer.validated_data['public_key'] - user.save() diff --git a/apps/users/models/user.py b/apps/users/models/user.py index 431a9789b..3fb058396 100644 --- a/apps/users/models/user.py +++ b/apps/users/models/user.py @@ -48,8 +48,9 @@ class AuthMixin: super().set_password(raw_password) def set_public_key(self, public_key): - self.public_key = public_key - self.save() + if self.can_update_ssh_key(): + self.public_key = public_key + self.save() def can_update_password(self): return self.is_local @@ -58,7 +59,7 @@ class AuthMixin: return self.can_use_ssh_key_login() def can_use_ssh_key_login(self): - return settings.TERMINAL_PUBLIC_KEY_AUTH + return self.is_local and settings.TERMINAL_PUBLIC_KEY_AUTH def is_public_key_valid(self): """