
- Complete FastAPI backend with SQLite database
- AI-powered resume parsing and job matching using OpenAI
- JWT authentication with role-based access control
- Resume upload, job management, and matching endpoints
- Recruiter dashboard with candidate ranking
- Analytics and skill gap analysis features
- Comprehensive API documentation with OpenAPI
- Alembic database migrations
- File upload support for PDF, DOCX, and TXT resumes
- CORS enabled for frontend integration
🤖 Generated with BackendIM
Co-Authored-By: Claude <noreply@anthropic.com>
56 lines
1.9 KiB
Python
56 lines
1.9 KiB
Python
from datetime import timedelta
|
|
from fastapi import APIRouter, Depends, HTTPException, status
|
|
from fastapi.security import OAuth2PasswordRequestForm
|
|
from sqlalchemy.orm import Session
|
|
from app.core.config import settings
|
|
from app.core.security import create_access_token, verify_password, get_password_hash
|
|
from app.core.deps import get_db
|
|
from app.models.user import User
|
|
from app.schemas.user import UserCreate, UserResponse, Token
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.post("/register", response_model=UserResponse)
|
|
def register(user: UserCreate, db: Session = Depends(get_db)):
|
|
"""Register a new user"""
|
|
# Check if user already exists
|
|
existing_user = db.query(User).filter(User.email == user.email).first()
|
|
if existing_user:
|
|
raise HTTPException(
|
|
status_code=400,
|
|
detail="Email already registered"
|
|
)
|
|
|
|
# Create new user
|
|
hashed_password = get_password_hash(user.password)
|
|
db_user = User(
|
|
email=user.email,
|
|
hashed_password=hashed_password,
|
|
full_name=user.full_name,
|
|
role=user.role
|
|
)
|
|
db.add(db_user)
|
|
db.commit()
|
|
db.refresh(db_user)
|
|
|
|
return db_user
|
|
|
|
|
|
@router.post("/login", response_model=Token)
|
|
def login(form_data: OAuth2PasswordRequestForm = Depends(), db: Session = Depends(get_db)):
|
|
"""Login and get access token"""
|
|
user = db.query(User).filter(User.email == form_data.username).first()
|
|
if not user or not verify_password(form_data.password, user.hashed_password):
|
|
raise HTTPException(
|
|
status_code=status.HTTP_401_UNAUTHORIZED,
|
|
detail="Incorrect email or password",
|
|
headers={"WWW-Authenticate": "Bearer"},
|
|
)
|
|
|
|
access_token_expires = timedelta(minutes=settings.ACCESS_TOKEN_EXPIRE_MINUTES)
|
|
access_token = create_access_token(
|
|
subject=user.email, expires_delta=access_token_expires
|
|
)
|
|
|
|
return {"access_token": access_token, "token_type": "bearer"} |