login endpont
This commit is contained in:
@@ -17,3 +17,22 @@ def create_user(username, password):
|
|||||||
)
|
)
|
||||||
|
|
||||||
return user_id
|
return user_id
|
||||||
|
|
||||||
|
def verify_user(username, password):
|
||||||
|
from database import fetch_one
|
||||||
|
|
||||||
|
user = fetch_one(
|
||||||
|
"SELECT * FROM users WHERE username = ?",
|
||||||
|
(username,)
|
||||||
|
)
|
||||||
|
|
||||||
|
if not user:
|
||||||
|
return None
|
||||||
|
|
||||||
|
if bcrypt.checkpw(
|
||||||
|
password.encode(),
|
||||||
|
user["password_hash"].encode()
|
||||||
|
):
|
||||||
|
return user["id"]
|
||||||
|
|
||||||
|
return None
|
||||||
@@ -5,6 +5,10 @@ from database import fetch_all
|
|||||||
from events import create_event
|
from events import create_event
|
||||||
from auth import create_user
|
from auth import create_user
|
||||||
|
|
||||||
|
class Login(BaseModel):
|
||||||
|
username: str
|
||||||
|
password: str
|
||||||
|
|
||||||
class UserCreate(BaseModel):
|
class UserCreate(BaseModel):
|
||||||
username: str
|
username: str
|
||||||
password: str
|
password: str
|
||||||
@@ -90,3 +94,7 @@ def api_create_user(user: UserCreate):
|
|||||||
"status": "created",
|
"status": "created",
|
||||||
"user_id": user_id
|
"user_id": user_id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@app.post("/login")
|
||||||
|
def api_login(login : Login):
|
||||||
|
|
||||||
Binary file not shown.
Reference in New Issue
Block a user