fix-scheme

This commit is contained in:
tonyrewin 2022-11-08 18:50:28 +03:00
parent 9052872c87
commit 5bf3621724
5 changed files with 17 additions and 12 deletions

View File

@ -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:

View File

@ -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:

View File

@ -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

View File

@ -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!

View File

@ -1,5 +1,7 @@
import sys
import uvicorn
from settings import PORT
if __name__ == "__main__":