首次提交
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
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()
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
from repositories.user_repo import UserRepository
|
||||
|
||||
class UserService:
|
||||
|
||||
@staticmethod
|
||||
def list_users():
|
||||
users = UserRepository.find_all()
|
||||
return [u.to_dict() for u in users]
|
||||
Reference in New Issue
Block a user