diff --git a/auth/authenticate.py b/auth/authenticate.py index 958560cb..425b5d1d 100644 --- a/auth/authenticate.py +++ b/auth/authenticate.py @@ -9,7 +9,7 @@ from starlette.requests import HTTPConnection from auth.credentials import AuthCredentials, AuthUser from auth.jwtcodec import JWTCodec from auth.tokenstorage import TokenStorage -from base.exceptions import InvalidToken +from base.exceptions import ExpiredToken, InvalidToken from services.auth.users import UserStorage from settings import SESSION_TOKEN_HEADER @@ -33,12 +33,12 @@ class SessionToken: except ExpiredSignatureError: payload = JWTCodec.decode(token, verify_exp=False) if not await cls.get(payload.user_id, token): - raise InvalidToken("Session token has expired, please try again") + raise ExpiredToken("Token signature has expired, please try again") except DecodeError as e: raise InvalidToken("token format error") from e else: if not await cls.get(payload.user_id, token): - raise InvalidToken("Session token has expired, please login again") + raise ExpiredToken("Session token has expired, please login again") return payload @classmethod diff --git a/auth/jwtcodec.py b/auth/jwtcodec.py index 130007fa..0c35dea5 100644 --- a/auth/jwtcodec.py +++ b/auth/jwtcodec.py @@ -8,10 +8,8 @@ from settings import JWT_ALGORITHM, JWT_SECRET_KEY class JWTCodec: @staticmethod def encode(user: AuthInput, exp: datetime) -> str: - issued = int(datetime.now().timestamp()) - print('[auth.jwtcodec] issued at %r' % issued) - expires = int(exp.timestamp()) - print('[auth.jwtcodec] expires at %r' % expires) + expires = int(exp.timestamp() * 1000) + issued = int(datetime.now().timestamp() * 1000) payload = { "user_id": user.id, "username": user.email or user.phone, @@ -42,8 +40,10 @@ class JWTCodec: print('[auth.jwtcodec] debug payload %r' % r) return r except jwt.InvalidIssuedAtError: + print('[auth.jwtcodec] invalid issued at: %r' % r) raise ExpiredToken('check token issued time') except jwt.ExpiredSignatureError: + print('[auth.jwtcodec] expired signature %r' % r) raise ExpiredToken('check token lifetime') except jwt.InvalidTokenError: raise InvalidToken('token is not valid') diff --git a/auth/tokenstorage.py b/auth/tokenstorage.py index c27c7d97..0d7a30e9 100644 --- a/auth/tokenstorage.py +++ b/auth/tokenstorage.py @@ -42,7 +42,7 @@ class TokenStorage: payload = JWTCodec.decode(token) except: # noqa pass - finally: + else: await redis.execute("DEL", f"{payload.user_id}-{token}") return True diff --git a/resolvers/zine/topics.py b/resolvers/zine/topics.py index 47e6643c..81db4f91 100644 --- a/resolvers/zine/topics.py +++ b/resolvers/zine/topics.py @@ -6,7 +6,7 @@ from base.resolvers import mutation, query from orm import Shout from orm.topic import Topic, TopicFollower from services.zine.topics import TopicStorage -from services.stat.reacted import ReactedStorage +# from services.stat.reacted import ReactedStorage from services.stat.topicstat import TopicStat @@ -19,9 +19,9 @@ async def get_topic_stat(slug): "authors": len(TopicStat.authors_by_topic.get(slug, {}).keys()), "followers": len(TopicStat.followers_by_topic.get(slug, {}).keys()), # "viewed": await ViewedStorage.get_topic(slug), - "reacted": len(await ReactedStorage.get_topic(slug)), - "commented": len(await ReactedStorage.get_topic_comments(slug)), - "rating": await ReactedStorage.get_topic_rating(slug) + # "reacted": len(await ReactedStorage.get_topic(slug)), + # "commented": len(await ReactedStorage.get_topic_comments(slug)), + # "rating": await ReactedStorage.get_topic_rating(slug) } diff --git a/schema.graphql b/schema.graphql index 1b644df1..e42e61db 100644 --- a/schema.graphql +++ b/schema.graphql @@ -477,9 +477,9 @@ type TopicStat { followers: Int! authors: Int! # viewed: Int - reacted: Int! - commented: Int - rating: Int + # reacted: Int! + #commented: Int + # rating: Int } type Topic {