Spaces:
Building
Building
Delete auth_controller.py
Browse files- auth_controller.py +0 -26
auth_controller.py
DELETED
@@ -1,26 +0,0 @@
|
|
1 |
-
from fastapi import APIRouter, Depends, HTTPException
|
2 |
-
from config_provider import get_config, ServiceConfig
|
3 |
-
from pydantic import BaseModel
|
4 |
-
import hashlib
|
5 |
-
|
6 |
-
router = APIRouter()
|
7 |
-
|
8 |
-
class LoginRequest(BaseModel):
|
9 |
-
username: str
|
10 |
-
password: str
|
11 |
-
|
12 |
-
def verify_password(stored_hash, input_password):
|
13 |
-
# Basit SHA256 hash kontrolü (salt + hash mekanizması uygulanabilir)
|
14 |
-
input_hash = hashlib.sha256(input_password.encode()).hexdigest()
|
15 |
-
return stored_hash == input_hash
|
16 |
-
|
17 |
-
@router.post("/auth/login")
|
18 |
-
def login(request: LoginRequest, config: ServiceConfig = Depends(get_config)):
|
19 |
-
user = next((u for u in config.data.get('users', []) if u['username'] == request.username), None)
|
20 |
-
if not user:
|
21 |
-
raise HTTPException(status_code=401, detail="Invalid username or password")
|
22 |
-
|
23 |
-
if not verify_password(user['password_hash'], request.password):
|
24 |
-
raise HTTPException(status_code=401, detail="Invalid username or password")
|
25 |
-
|
26 |
-
return { "status": "success" }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|