Package backend.logic

Klasse UserService

java.lang.Object
backend.logic.UserService

public class UserService extends Object
Service class for managing user-related operations including authentication, retrieval, and modification of user data. Handles database interactions for user management and provides session management through authentication.
  • Konstruktordetails

    • UserService

      public UserService()
  • Methodendetails

    • setConnectionProvider

      public static void setConnectionProvider(ConnectionProvider provider)
      secures DatabaseConnection
    • authenticate

      public static User authenticate(String email, String password) throws AuthenticationException
      Authenticates a user with the provided email and password.
      Parameter:
      email - The user's email address
      password - The user's password (plaintext)
      Gibt zurück:
      The authenticated User object
      Löst aus:
      AuthenticationException - If authentication fails due to invalid credentials, account status, or database errors
      IllegalStateException - If the connection provider is not set
    • getAllUsers

      public static List<User> getAllUsers()
      Retrieves all users from the database.
      Gibt zurück:
      List of all User objects in the system
      Löst aus:
      IllegalStateException - If the connection provider is not set
    • getUserById

      public static User getUserById(int userId)
      Retrieves a user by his unique ID.
      Parameter:
      userId - The ID of the user to retrieve
      Gibt zurück:
      User object with the specified ID, or empty User object if not found
    • updateUser

      public void updateUser(User editedUser)
      Updates an existing user's information in the database.
      Parameter:
      editedUser - The User object containing updated information
      Löst aus:
      IllegalStateException - If the connection provider is not set
    • insertUser

      public void insertUser(User newUser)
      Creates a new user in the database.
      Parameter:
      newUser - The User object to be created
      Löst aus:
      IllegalStateException - If the connection provider is not set
    • getAllUsersEmail

      public static List<String> getAllUsersEmail()
      Retrieves all user email addresses from the database.
      Gibt zurück:
      List of all email addresses in the system
    • getUserIdByEmail

      public static int getUserIdByEmail(String email)
      Retrieves a user's ID by their email address.
      Parameter:
      email - The email address to search for
      Gibt zurück:
      The user ID if found, or -1 if not found
    • getUserByEmail

      public static User getUserByEmail(String email)
      Retrieves a complete user object by email address.
      Parameter:
      email - The email address to search for
      Gibt zurück:
      User object if found, or null if not found
      Löst aus:
      IllegalStateException - If the connection provider is not set