Update code in endpoints/login.post.py
This commit is contained in:
parent
508ccb71ec
commit
e9d79b2cc8
@ -1,25 +1,50 @@
|
|||||||
from fastapi import APIRouter, Depends, HTTPException
|
from fastapi import APIRouter, Depends, HTTPException
|
||||||
from core.auth import get_current_user_dummy
|
|
||||||
from core.database import fake_users_db
|
from core.database import fake_users_db
|
||||||
|
import uuid
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
@router.post("/login")
|
@router.post("/api/employees")
|
||||||
async def login_demo(
|
async def create_employee(
|
||||||
username: str = "demo",
|
name: str,
|
||||||
password: str = "password"
|
position: str,
|
||||||
|
email: str,
|
||||||
|
department: Optional[str] = None,
|
||||||
|
salary: Optional[float] = None
|
||||||
):
|
):
|
||||||
"""Demo login endpoint"""
|
"""Create new employee record"""
|
||||||
user = fake_users_db.get(username)
|
employee_id = str(uuid.uuid4())
|
||||||
if not user or user["password"] != password:
|
|
||||||
raise HTTPException(status_code=400, detail="Invalid credentials")
|
if email in [emp.get("email") for emp in fake_users_db.values()]:
|
||||||
|
raise HTTPException(status_code=400, detail="Employee with this email already exists")
|
||||||
|
|
||||||
|
employee_data = {
|
||||||
|
"id": employee_id,
|
||||||
|
"name": name,
|
||||||
|
"position": position,
|
||||||
|
"email": email,
|
||||||
|
"department": department,
|
||||||
|
"salary": salary,
|
||||||
|
"active": True
|
||||||
|
}
|
||||||
|
|
||||||
|
fake_users_db[employee_id] = employee_data
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"message": "Login successful (demo)",
|
"message": "Employee created successfully",
|
||||||
"user": username,
|
"data": {
|
||||||
"token": "dummy_jwt_token_123",
|
"employee_id": employee_id,
|
||||||
"features": {
|
"name": name,
|
||||||
"rate_limit": 100,
|
"email": email
|
||||||
"expires_in": 3600
|
},
|
||||||
}
|
"metadata": {
|
||||||
}
|
"created_at": "demo_timestamp",
|
||||||
|
"department": department
|
||||||
|
},
|
||||||
|
"next_steps": [
|
||||||
|
"Complete employee onboarding",
|
||||||
|
"Assign access credentials",
|
||||||
|
"Schedule orientation"
|
||||||
|
]
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user