67 lines
2.1 KiB
Python
67 lines
2.1 KiB
Python
from sqlalchemy.orm import Session
|
|
from app.modules.auth.models.user_model import User
|
|
from app.modules.auth.services.auth_service import AuthService, UserService
|
|
from typing import Any, Optional
|
|
|
|
|
|
class AuthController:
|
|
@staticmethod
|
|
def register_user(payload: Any, tenant: Any, db: Session):
|
|
auth_service = AuthService(db)
|
|
return auth_service.register(payload, tenant)
|
|
|
|
@staticmethod
|
|
def login_user(form_data: Any, db: Session, request: Optional[Any] = None):
|
|
auth_service = AuthService(db)
|
|
return auth_service.login(form_data.username, form_data.password, request)
|
|
|
|
@staticmethod
|
|
def google_login(payload: Any, db: Session, request: Optional[Any] = None):
|
|
auth_service = AuthService(db)
|
|
return auth_service.google_login(payload, request)
|
|
|
|
@staticmethod
|
|
def forgot_password(payload: Any, db: Session):
|
|
auth_service = AuthService(db)
|
|
return auth_service.forgot_password(payload)
|
|
|
|
@staticmethod
|
|
def reset_password(payload: Any, db: Session):
|
|
auth_service = AuthService(db)
|
|
return auth_service.reset_password(payload)
|
|
|
|
|
|
class UserController:
|
|
@staticmethod
|
|
def update_profile(
|
|
user: User,
|
|
name: Optional[str],
|
|
db: Session,
|
|
designation: Optional[str] = None,
|
|
preferred_language: Optional[str] = None,
|
|
):
|
|
user_service = UserService(db)
|
|
return user_service.update_profile(
|
|
user,
|
|
name=name,
|
|
designation=designation,
|
|
preferred_language=preferred_language,
|
|
)
|
|
|
|
@staticmethod
|
|
def change_password(
|
|
user: User, current_password: str, new_password: str, db: Session
|
|
):
|
|
user_service = UserService(db)
|
|
return user_service.change_password(user, current_password, new_password)
|
|
|
|
@staticmethod
|
|
def get_user_stats(user: User, db: Session):
|
|
user_service = UserService(db)
|
|
return user_service.get_user_stats(user)
|
|
|
|
@staticmethod
|
|
def delete_account(user: User, db: Session):
|
|
user_service = UserService(db)
|
|
return user_service.delete_account(user)
|