Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.idea/
__pycache__/
28 changes: 28 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
poetry
passlib[bcrypt]
black
pytest
fastapi
uvicorn
httpie
requests
httpx
mypy
python-jose[cryptography]
python-multipart
pytest-mock
hypothesis
schemathesis
locust
locust-grasshopper
uvicorn[standard]
gunicorn
torch
torchvision
transformers
aiofiles
tabulate
plotly
kaleido
pydantic
country_converter
5 changes: 4 additions & 1 deletion src/data/user.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from model.user import User
from .init import (curs, IntegrityError)
from .init import (curs, IntegrityError,conn)
from error import Missing, Duplicate

curs.execute("""create table if not exists
Expand Down Expand Up @@ -44,6 +44,7 @@ def create(user: User, table:str = "user") -> User:
params = model_to_dict(user)
try:
curs.execute(qry, params)
conn.commit()
except IntegrityError:
raise Duplicate(msg=
f"{table}: user {user.name} already exists")
Expand All @@ -59,6 +60,7 @@ def modify(name: str, user: User) -> User:
"name0": name}
curs.execute(qry, params)
if curs.rowcount == 1:
conn.commit()
return get_one(user.name)
else:
raise Missing(msg=f"User {name} not found")
Expand All @@ -72,3 +74,4 @@ def delete(name: str) -> None:
if curs.rowcount != 1:
raise Missing(msg=f"User {name} not found")
create(user, table="xuser")
conn.commit()
Binary file modified src/db/cryptid.db
Binary file not shown.
7 changes: 5 additions & 2 deletions src/service/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def get_current_user(token: str) -> User | None:

def lookup_user(name: str) -> User | None:
"""Return a matching User fron the database for <name>"""
if (user := data.get(name)):
if (user := data.get_one(name)):
return user
return None

Expand All @@ -63,7 +63,7 @@ def create_access_token(data: dict,
):
"""Return a JWT access token"""
src = data.copy()
now = datetime.utcnow()
now = datetime.datetime.utcnow()
expires = expires or datetime.timedelta(minutes=TOKEN_EXPIRES)
src.update({"exp": now + expires})
encoded_jwt = jwt.encode(src, SECRET_KEY, algorithm=ALGORITHM)
Expand All @@ -78,6 +78,9 @@ def get_one(name) -> User:
return data.get_one(name)

def create(user: User) -> User:
plain_password = user.hash
hashed_password = get_hash(plain_password)
user.hash = hashed_password
return data.create(user)

def modify(name: str, user: User) -> User:
Expand Down
2 changes: 1 addition & 1 deletion src/web/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ async def create_access_token(
unauthed()
expires = timedelta(minutes=ACCESS_TOKEN_EXPIRE_MINUTES)
access_token = service.create_access_token(
data={"sub": user.username}, expires=expires
data={"sub": user.name}, expires=expires
)
return {"access_token": access_token, "token_type": "bearer"}

Expand Down