61 lines
1.8 KiB
Python
61 lines
1.8 KiB
Python
from fastapi import APIRouter, BackgroundTasks
|
|
from services.authService import AuthService
|
|
from schemas.CreateSchemas import UserCreate
|
|
from schemas.ApiResponse import ApiResponse
|
|
from schemas.BaseSchemas import AuthBase, AuthOTP, ResetPasswordBase
|
|
from services.clinicServices import ClinicServices
|
|
|
|
router = APIRouter()
|
|
|
|
@router.post("/login")
|
|
async def login(data: AuthBase):
|
|
token = await AuthService().login(data)
|
|
return ApiResponse(
|
|
data=token,
|
|
message="Login successful"
|
|
)
|
|
|
|
|
|
@router.post("/register")
|
|
async def register(user_data: UserCreate, background_tasks: BackgroundTasks):
|
|
token = await AuthService().register(user_data, background_tasks)
|
|
return ApiResponse(
|
|
data=token,
|
|
message="User registered successfully"
|
|
)
|
|
|
|
@router.get("/clinic/latest-id")
|
|
async def get_latest_clinic_id():
|
|
clinic_id = await ClinicServices().get_latest_clinic_id()
|
|
return ApiResponse(
|
|
data=clinic_id,
|
|
message="Latest clinic ID retrieved successfully"
|
|
)
|
|
|
|
|
|
@router.post('/admin/forget-password')
|
|
async def forget_password(email: str):
|
|
await AuthService().forget_password(email)
|
|
return ApiResponse(data="OK", message="Password reset email sent successfully")
|
|
|
|
@router.post('/admin/reset-password')
|
|
async def reset_password(data: ResetPasswordBase):
|
|
await AuthService().reset_password(data.token, data.password)
|
|
return ApiResponse(data="OK", message="Password reset successfully")
|
|
|
|
|
|
@router.post("/send-otp")
|
|
async def send_otp(email: str):
|
|
await AuthService().send_otp(email)
|
|
return ApiResponse(
|
|
data="OK",
|
|
message="OTP sent successfully"
|
|
)
|
|
|
|
@router.post("/verify-otp")
|
|
async def verify_otp(data: AuthOTP):
|
|
await AuthService().verify_otp(data)
|
|
return ApiResponse(
|
|
data="OK",
|
|
message="OTP verified successfully"
|
|
) |