diff --git a/auth/identity.py b/auth/identity.py index f6310469..c2526863 100644 --- a/auth/identity.py +++ b/auth/identity.py @@ -1,24 +1,27 @@ from jwt import DecodeError, ExpiredSignatureError +from passlib.hash import bcrypt from sqlalchemy import or_ from auth.jwtcodec import JWTCodec from auth.tokenstorage import TokenStorage -from validations.auth import AuthInput -from base.exceptions import InvalidPassword -from base.exceptions import InvalidToken +from base.exceptions import InvalidPassword, InvalidToken from base.orm import local_session from orm import User -from passlib.hash import bcrypt +from validations.auth import AuthInput class Password: @staticmethod def encode(password: str) -> str: + + # TODO: sha256 -> hexdigest -> bcrypt return bcrypt.hash(password) @staticmethod - def verify(password: str, other: str) -> bool: - return bcrypt.verify(password, other) + def verify(password: str, hashed: str) -> bool: + # TODO: detect rounds amount + # TODO: sha256 -> hexdigest -> bcrypt + return bcrypt.verify(password, hashed) class Identity: diff --git a/migration/tables/users.py b/migration/tables/users.py index 811ffce0..982f3abc 100644 --- a/migration/tables/users.py +++ b/migration/tables/users.py @@ -3,7 +3,7 @@ from sqlalchemy.exc import IntegrityError from base.orm import local_session from migration.html2text import html2text -from orm.user import User, UserRating, AuthorFollower +from orm.user import AuthorFollower, User, UserRating def migrate(entry): @@ -16,7 +16,6 @@ def migrate(entry): "ratings": [], "username": email, "email": email, - "password": entry["services"]["password"].get("bcrypt", ""), "createdAt": parse(entry["createdAt"]), "emailConfirmed": bool(entry["emails"][0]["verified"]), "muted": False, # amnesty @@ -25,6 +24,7 @@ def migrate(entry): "links": [], "name": "anonymous", } + user_dict["password"] = entry["services"]["password"].get("bcrypt") if "updatedAt" in entry: user_dict["updatedAt"] = parse(entry["updatedAt"]) if "wasOnineAt" in entry: diff --git a/resolvers/inbox.py b/resolvers/inbox.py index b6e7d210..64063d54 100644 --- a/resolvers/inbox.py +++ b/resolvers/inbox.py @@ -107,7 +107,7 @@ async def create_chat(_, info, title="", members=[]): } -async def load_messages(chatId: int, offset: int, amount: int): +async def load_messages(chatId: str, offset: int, amount: int): messages = [] message_ids = await redis.lrange( f"chats/{chatId}/message_ids", 0 - offset - amount, 0 - offset diff --git a/schema.graphql b/schema.graphql index dce30611..a4a42f2b 100644 --- a/schema.graphql +++ b/schema.graphql @@ -197,8 +197,8 @@ type Mutation { type Query { # inbox - myChats: [Chat]! - loadChat(chatId: String!, offset: Int, amount: Int): [Message]! + myChats: Result! + loadChat(chatId: String!, offset: Int, amount: Int): Result! # auth isEmailUsed(email: String!): Boolean! @@ -487,7 +487,7 @@ type Message { } type Chat { - id: Int! + id: String! createdAt: Int! createdBy: User! updatedAt: Int! diff --git a/server.py b/server.py index 1e8502e1..7f92c3c9 100644 --- a/server.py +++ b/server.py @@ -1,5 +1,7 @@ import sys + import uvicorn + from settings import PORT if __name__ == "__main__":