refactor(tokens-repo): rewrite token refresh

now it is not json-dependent.
This commit is contained in:
Houkime 2022-12-12 11:15:25 +00:00
parent 27a7c24bc3
commit 572ec75c39

View file

@ -71,16 +71,10 @@ class JsonTokensRepository(AbstractTokensRepository):
"""Change the token field of the existing token""" """Change the token field of the existing token"""
new_token = Token.generate(device_name=input_token.device_name) new_token = Token.generate(device_name=input_token.device_name)
with WriteUserData(UserDataFiles.TOKENS) as tokens_file: if input_token in self.get_tokens():
for userdata_token in tokens_file["tokens"]: self.delete_token(input_token)
self.__store_token(new_token)
if userdata_token["name"] == input_token.device_name: return new_token
userdata_token["token"] = new_token.token
userdata_token["date"] = (
new_token.created_at.strftime(DATETIME_FORMAT),
)
return new_token
raise TokenNotFound("Token not found!") raise TokenNotFound("Token not found!")