48 lines
1.2 KiB
Python
48 lines
1.2 KiB
Python
# from app.models.user_model import User
|
|
# from app.services.db_service import db
|
|
# import logging
|
|
|
|
# class UserService:
|
|
|
|
# @staticmethod
|
|
# def register_user(name, email, password):
|
|
# user = User(name=name, email=email)
|
|
# user.set_password(password)
|
|
# db.session.add(user)
|
|
# db.session.commit()
|
|
# logging.info(f"New user registered: {email}")
|
|
# return user
|
|
|
|
# @staticmethod
|
|
# def validate_login(email, password):
|
|
# user = User.query.filter_by(email=email).first()
|
|
# if user and user.check_password(password):
|
|
# logging.info(f"Login success: {email}")
|
|
# return user
|
|
# logging.warning(f"Login failed for: {email}")
|
|
# return None
|
|
|
|
# @staticmethod
|
|
# def get_all_users():
|
|
# return User.query.all()
|
|
|
|
|
|
from app.services.db_service import DBService
|
|
from app.models.user_model import User
|
|
|
|
class UserService:
|
|
|
|
def get_all_users(self):
|
|
db = DBService().connect()
|
|
cursor = db.cursor(dictionary=True)
|
|
|
|
cursor.execute("SELECT id, name, email FROM users")
|
|
rows = cursor.fetchall()
|
|
|
|
users = [User(**row) for row in rows]
|
|
|
|
cursor.close()
|
|
db.close()
|
|
|
|
return users
|