diff --git a/apps/authentication/api/token.py b/apps/authentication/api/token.py index d8e8eb6fc..c46c4d5e2 100644 --- a/apps/authentication/api/token.py +++ b/apps/authentication/api/token.py @@ -33,8 +33,8 @@ class TokenCreateApi(AuthMixin, CreateAPIView): self.check_user_mfa_if_need(user) self.check_user_login_confirm_if_need(user) self.send_auth_signal(success=True, user=user) - self.clear_auth_mark() resp = super().create(request, *args, **kwargs) + self.clear_auth_mark() return resp except errors.AuthFailedError as e: return Response(e.as_data(), status=400) diff --git a/apps/authentication/serializers.py b/apps/authentication/serializers.py index a87e1e942..44fea3242 100644 --- a/apps/authentication/serializers.py +++ b/apps/authentication/serializers.py @@ -54,9 +54,9 @@ class BearerTokenSerializer(serializers.Serializer): user.last_login = timezone.now() user.save(update_fields=['last_login']) - def create(self, validated_data): + def get_request_user(self): request = self.context.get('request') - if request.user and not request.user.is_anonymous: + if request.user and request.user.is_authenticated: user = request.user else: user_id = request.session.get('user_id') @@ -65,6 +65,12 @@ class BearerTokenSerializer(serializers.Serializer): raise serializers.ValidationError( "user id {} not exist".format(user_id) ) + return user + + def create(self, validated_data): + request = self.context.get('request') + user = self.get_request_user() + token, date_expired = user.create_bearer_token(request) self.update_last_login(user) diff --git a/apps/locale/zh/LC_MESSAGES/django.mo b/apps/locale/zh/LC_MESSAGES/django.mo index 03f88c57e..2aec9545b 100644 --- a/apps/locale/zh/LC_MESSAGES/django.mo +++ b/apps/locale/zh/LC_MESSAGES/django.mo @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:925c5a219a4ee6835ad59e3b8e9f7ea5074ee3df6527c0f73ef1a50eaedaf59c -size 91777 +oid sha256:fd23c3a1a8f833e99937d38db94b5e32b308c9c1912f8b258ff009d96f9bf2bb +size 92755 diff --git a/apps/locale/zh/LC_MESSAGES/django.po b/apps/locale/zh/LC_MESSAGES/django.po index 4305720a7..e5071bf14 100644 --- a/apps/locale/zh/LC_MESSAGES/django.po +++ b/apps/locale/zh/LC_MESSAGES/django.po @@ -3240,7 +3240,7 @@ msgstr "" #: settings/serializers/other.py:24 msgid "Shell (Windows)" -msgstr "Shell(Windows 资产)" +msgstr "Windows shell" #: settings/serializers/other.py:25 msgid "The shell type used when Windows assets perform ansible tasks" @@ -3248,15 +3248,15 @@ msgstr "windows 资产执行 Ansible 任务时,使用的 Shell 类型。" #: settings/serializers/other.py:29 msgid "Perm ungroup node" -msgstr "授权未分组节点" +msgstr "显示未分组节点" #: settings/serializers/other.py:30 msgid "Perm single to ungroup node" -msgstr "授权未分组节点" +msgstr "放置单独授权的资产到未分组节点, 避免能看到资产所在节点,但该节点未被授权的问题" #: settings/serializers/other.py:34 msgid "Help Docs URL" -msgstr "" +msgstr "文档链接" #: settings/serializers/other.py:35 msgid "default: http://docs.jumpserver.org"