Browse Source

fix: 修复创建token的问题

pull/7176/head
ibuler 3 years ago committed by xinwen
parent
commit
353b66bf8f
  1. 2
      apps/authentication/api/token.py
  2. 10
      apps/authentication/serializers.py
  3. 4
      apps/locale/zh/LC_MESSAGES/django.mo
  4. 8
      apps/locale/zh/LC_MESSAGES/django.po

2
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)

10
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)

4
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

8
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"

Loading…
Cancel
Save