data-manager/services/auth_service.py

23 lines
624 B
Python
Raw Permalink Normal View History

2026-01-08 10:25:45 +08:00
from repositories.user_repo import UserRepository
from common.exceptions import BusinessException
from flask_jwt_extended import create_access_token
class AuthService:
@staticmethod
def login(username: str, password: str):
user = UserRepository.find_by_username(username)
if not user:
raise BusinessException(40101, "User not found")
if user.password != password:
raise BusinessException(40102, "Invalid credentials")
token = create_access_token(identity=user.id)
return {
"token": token,
"user": user.to_dict()
}