From 572ec75c39db21c05282bde443276092b14a5f0a Mon Sep 17 00:00:00 2001 From: Houkime <> Date: Mon, 12 Dec 2022 11:15:25 +0000 Subject: [PATCH] refactor(tokens-repo): rewrite token refresh now it is not json-dependent. --- .../repositories/tokens/json_tokens_repository.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/selfprivacy_api/repositories/tokens/json_tokens_repository.py b/selfprivacy_api/repositories/tokens/json_tokens_repository.py index e011b62..2f4a0b1 100644 --- a/selfprivacy_api/repositories/tokens/json_tokens_repository.py +++ b/selfprivacy_api/repositories/tokens/json_tokens_repository.py @@ -71,16 +71,10 @@ class JsonTokensRepository(AbstractTokensRepository): """Change the token field of the existing token""" new_token = Token.generate(device_name=input_token.device_name) - with WriteUserData(UserDataFiles.TOKENS) as tokens_file: - for userdata_token in tokens_file["tokens"]: - - if userdata_token["name"] == input_token.device_name: - userdata_token["token"] = new_token.token - userdata_token["date"] = ( - new_token.created_at.strftime(DATETIME_FORMAT), - ) - - return new_token + if input_token in self.get_tokens(): + self.delete_token(input_token) + self.__store_token(new_token) + return new_token raise TokenNotFound("Token not found!")