login endpont
This commit is contained in:
+20
-1
@@ -16,4 +16,23 @@ def create_user(username, password):
|
||||
(username, password_hash)
|
||||
)
|
||||
|
||||
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
|
||||
+9
-1
@@ -5,6 +5,10 @@ from database import fetch_all
|
||||
from events import create_event
|
||||
from auth import create_user
|
||||
|
||||
class Login(BaseModel):
|
||||
username: str
|
||||
password: str
|
||||
|
||||
class UserCreate(BaseModel):
|
||||
username: str
|
||||
password: str
|
||||
@@ -89,4 +93,8 @@ def api_create_user(user: UserCreate):
|
||||
return {
|
||||
"status": "created",
|
||||
"user_id": user_id
|
||||
}
|
||||
}
|
||||
|
||||
@app.post("/login")
|
||||
def api_login(login : Login):
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user