man*_*eak 0 authentication django django-rest-framework django-allauth django-rest-auth
我正在使用Django,Django REST框架,Django-rest-auth和Django-allauth编写服务器应用程序。我有一种用于在用户之间传递消息的方法,只有在接收者登录后才应该发生这种情况。
但是,is_authenticated()即使用户已注销(似乎叫rest-auth/logout/,该对象又应调用Django的注销),该用户对象的方法似乎仍返回True 。是什么原因造成的?我在这里想念什么吗?
这是我的代码:
class SendMessage(generics.CreateAPIView):
permission_classes = (permissions.IsAuthenticated,)
serializer_class = MessageSerializer
def perform_create(self, serializer):
m = self.request.data['msg']
targetUser = User.objects.get(pk = self.request.data['user'])
if targetUser.is_authenticated():
# Send message
else:
# Don't send message
Run Code Online (Sandbox Code Playgroud)
不幸的是,is_authenticated()方法始终返回true。
def is_authenticated(self):
"""
Always return True. This is a way to tell if the user has been
authenticated in templates.
"""
return True
Run Code Online (Sandbox Code Playgroud)
它旨在区分用户实例和AnonymousUser实例,这是当用户未通过身份验证时将其设置为的名称。
| 归档时间: |
|
| 查看次数: |
895 次 |
| 最近记录: |