Skip to content

Commit

Permalink
refactoring User model token related methods
Browse files Browse the repository at this point in the history
  • Loading branch information
snyaggarwal committed Aug 27, 2020
1 parent 36a6679 commit 337dc66
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions core/users/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,21 @@ def update_password(self, password=None, hashed_password=None):

def refresh_token(self):
Token.objects.filter(user=self).delete()
Token.objects.create(user=self)
self.__create_token()

def get_token(self):
token = Token.objects.filter(user_id=self.id).first()
if not token:
token = Token.objects.create(user=self)
token = Token.objects.filter(user_id=self.id).first() or self.__create_token()
return token.key

def __str__(self):
return str(self.mnemonic)

def is_admin_for(self, concept_container):
parent_id = concept_container.parent_id
return parent_id == self.id or self.organizations.filter(id=parent_id).exists()

def __create_token(self):
return Token.objects.create(user=self)

def __str__(self):
return str(self.mnemonic)


admin.site.register(UserProfile)

0 comments on commit 337dc66

Please sign in to comment.