Class SecureUserService

java.lang.Object
de.bytestore.hostinger.security.service.SecureUserService

@Service @Component public class SecureUserService extends Object
  • Constructor Details

    • SecureUserService

      public SecureUserService()
  • Method Details

    • onApplicationStarted

      @EventListener public void onApplicationStarted(org.springframework.boot.context.event.ApplicationStartedEvent event)
    • registerUser

      public void registerUser(String emailIO, String passwordIO)
      Registers a new user with the provided email and password, sets the user as inactive, saves the user to the data store, and sends a verification email to the user's email address.
      Parameters:
      emailIO - The email address of the new user.
      passwordIO - The password for the new user.
    • purgeOldRegistrations

      public void purgeOldRegistrations()
      Purges old user registrations that have not been verified within the allowed time frame. This method identifies and deletes user entries from the system that are: 1. Marked as not verified. 2. Created earlier than the expiration time based on the maximum allowed verification time. The expiration time is calculated using the current time minus the configuration value specified in registerSettings.getMaxRegisterVerifyTime(). Logs the number of users deleted and the verification time limit for reference. The deletion process is performed for each user meeting the criteria.
    • getUsersByRole

      public List<User> getUsersByRole(String roleName)
      Retrieves a list of users who have the specified role.
      Parameters:
      roleName - the name of the role to filter users by
      Returns:
      a list of users who are associated with the specified role
    • getUserById

      public Optional<User> getUserById(UUID idIO)
      Retrieves a user by their unique identifier.
      Parameters:
      idIO - the unique identifier of the user to be retrieved
      Returns:
      an Optional containing the User if found, otherwise an empty Optional
    • verifyUser

      public boolean verifyUser(UUID parameter)
      Verifies the user associated with the given parameter. If the user is not already verified, the method activates the user and sets their verified status to true.
      Parameters:
      parameter - the identifier of the user to be verified
      Returns:
      true if the user was successfully verified, false if the user does not exist or is already verified
    • getNewUsersByMonth

      public List<User> getNewUsersByMonth()
      Retrieves a list of new users created within the current month.
      Returns:
      A list of new users.
    • getSettingsOrEmpty

      public String getSettingsOrEmpty(User userIO, String keyIO)
      Retrieves the value of a specific setting for a given
    • setSettingsOrCreate

      public void setSettingsOrCreate(User userIO, String keyIO, String valueIO)
      Sets the value of a specific setting for a given User. If the UserSettings object does not exist, it creates a new one and saves it to the database.
      Parameters:
      userIO - the User object for which the setting is being set
      keyIO - the key of the setting
      valueIO - the value of the setting
    • removeSettings

      public void removeSettings(User userIO, String keyIO)
      This method removes the settings for a specific key belonging to a user.
      Parameters:
      userIO - the User object for which the settings are being removed
      keyIO - the key of the setting to be removed
    • getStuffs

      public List<User> getStuffs()
    • getUsernames

      public List<String> getUsernames(List<User> stuffsIO)
    • broadcast

      public void broadcast(List<User> usersIO, String subjectIO, String messageIO)
      Sends a broadcast notification to multiple users.
      Parameters:
      usersIO - the list of users to send the notification to
      subjectIO - the subject of the notification
      messageIO - the message content of the notification
    • doUserExists

      public boolean doUserExists(String nameIO)
      Checks if a user with the given name exists.
      Parameters:
      nameIO - the name of the user to check
      Returns:
      true if a user with the given name exists, false otherwise
    • getUsersByName

      public List<User> getUsersByName(String nameIO)
      Retrieves a list of users by name.
      Parameters:
      nameIO - the name of the users to retrieve
      Returns:
      a list of users with the given name
    • createUser

      public void createUser(String nameIO, String passwordIO)
      Creates a new user with the given name and password.
      Parameters:
      nameIO - the name of the user
      passwordIO - the password of the user
    • killSessions

      public void killSessions(String nameIO)
      Kills all active sessions for the given username.
      Parameters:
      nameIO - the username for which the sessions should be killed
    • addRole

      public void addRole(String usernameIO, String roleIO, String typeIO)
      Adds a role to a user.
      Parameters:
      usernameIO - the username of the user
      roleIO - the role code to assign
      typeIO - the role type to assign
    • hasRole

      public boolean hasRole(String usernameIO, String roleIO, String typeIO)
      Checks if a user with the given username has a specific role with the given role code and role type.
      Parameters:
      usernameIO - the username of the user
      roleIO - the role code to check
      typeIO - the role type to check
      Returns:
      true if the user has the specified role, false otherwise
    • count

      public Object count()
      Returns the count of User objects in the database.
      Returns:
      the count of User objects
    • executeCreateWebhook

      public void executeCreateWebhook(io.jmix.core.event.EntitySavingEvent<User> event)
      Executes the create webhook for a given User entity saving event.
      Parameters:
      event - the EntitySavingEvent representing the save event for the User entity
    • executeUpdateWebhook

      public void executeUpdateWebhook(io.jmix.core.event.EntityChangedEvent<User> event)
      Executes the update webhook for a given User entity changed event.
      Parameters:
      event - the EntityChangedEvent representing the change in the User entity
    • webhooks

      public void webhooks()
    • sendVerification

      public void sendVerification(User userIO)
      Sends a verification email to the specified user.
      Parameters:
      userIO - the user object containing user details, including ID and email.
    • isEMail

      public boolean isEMail(String usernameIO)
      Checks if the given usernameIO is a valid email address based on the predefined EMAIL_REGEX pattern.
      Parameters:
      usernameIO - The string input to be validated as an email address.
      Returns:
      true if the input string matches the email pattern; false otherwise.
    • getUsersByMail

      public List<User> getUsersByMail(String emailIO)
      Retrieves a list of users filtered by their email addresses.
      Parameters:
      emailIO - the email address to filter users.
      Returns:
      a list of users with the specified email address.