Unverified Commit 7a133be7 authored by BaiJiangJie's avatar BaiJiangJie Committed by GitHub

[Update] 优化User操作private_token的接口 (#3091)

* [Update] 优化User操作private_token的接口

* [Update] 优化User操作private_token的接口 2
parent a654bbef
...@@ -207,20 +207,19 @@ class TokenMixin: ...@@ -207,20 +207,19 @@ class TokenMixin:
@property @property
def private_token(self): def private_token(self):
from authentication.models import PrivateToken return self.create_private_token()
try:
token = PrivateToken.objects.get(user=self)
except PrivateToken.DoesNotExist:
token = self.create_private_token()
return token
def create_private_token(self): def create_private_token(self):
from authentication.models import PrivateToken from authentication.models import PrivateToken
token = PrivateToken.objects.create(user=self) token, created = PrivateToken.objects.get_or_create(user=self)
return token return token
def delete_private_token(self):
from authentication.models import PrivateToken
PrivateToken.objects.filter(user=self).delete()
def refresh_private_token(self): def refresh_private_token(self):
self.private_token.delete() self.delete_private_token()
return self.create_private_token() return self.create_private_token()
def create_bearer_token(self, request=None): def create_bearer_token(self, request=None):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment