health-apps-backend/apis/endpoints/auth.py

59 lines
1.7 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
from http import HTTPStatus
router = APIRouter()
@router.post("/login")
def login(data: AuthBase):
token = AuthService().login(data)
return ApiResponse(
data=token,
message="Login successful"
)
@router.post("/register")
def register(user_data: UserCreate, background_tasks: BackgroundTasks):
token = AuthService().register(user_data, background_tasks)
return ApiResponse(
data=token,
message="User registered successfully"
)
@router.get("/clinic/latest-id")
def get_latest_clinic_id():
clinic_id = ClinicServices().get_latest_clinic_id()
return ApiResponse(
data=clinic_id,
message="Latest clinic ID retrieved successfully"
)
@router.post('/admin/forget-password')
def forget_password(email: str):
AuthService().forget_password(email)
return ApiResponse(data="OK", message="Password reset email sent successfully")
@router.post('/admin/reset-password')
def reset_password(data: ResetPasswordBase):
AuthService().reset_password(data.token, data.password)
return ApiResponse(data="OK", message="Password reset successfully")
@router.post("/send-otp")
def send_otp(email: str):
AuthService().send_otp(email)
return HTTPStatus.OK
@router.post("/verify-otp")
def verify_otp(data: AuthOTP):
AuthService().verify_otp(data)
return ApiResponse(
data="OK",
message="OTP verified successfully"
)