Global API refactoring

This commit is contained in:
2022-10-09 13:43:06 +03:00
parent ad659b5f30
commit 47359a7932
11 changed files with 471 additions and 213 deletions

View File

@@ -46,11 +46,15 @@ class UserToken(models.Model):
@staticmethod
def get_user_by_token(token: str):
t = UserToken.objects.filter(access_token=token)
return UserToken.get_by_token(token).user
@staticmethod
def get_by_token(token: str):
t = UserToken.objects.filter(access_token=token).select_related('user')
if len(t) == 0:
raise Exception(API_ERROR_INVALID_TOKEN)
return t[0].user
return t[0]
def __str__(self):
return self.user.email + ": " + self.access_token[:10] + "..."