src/main/java/sk/filo/plantdiary/service/UserService.java
public void activate(ActivateUserSO activateUserSO) {
        LOGGER.debug("activate({})", activateUserSO);
        User user = userRepository.findByUsernameAndUserActivationToken(activateUserSO.getUsername(), activateUserSO.getToken())
                    .orElseThrow(() -> new ResponseStatusException(HttpStatus.BAD_REQUEST, ExceptionCode.USER_NOT_FOUND.name()));

        user.setEnabled(true);
        user.setEmail(user.getUserActivation().getEmail()); // this is important when user only update email of existing account
        user.setUserActivation(null); // remove activation object
        userRepository.save(user);
    }
// activate new user by link from email, set enabled to true
activate new user by link from email, set enabled to true
activate new user by link from email set enabled to true
public void activate(ActivateUserSO activateUserSO) {
        LOGGER.debug("activate({})", activateUserSO);
        User user = userRepository.findByUsernameAndUserActivationToken(activateUserSO.getUsername(), activateUserSO.getToken())
                    .orElseThrow(() -> new ResponseStatusException(HttpStatus.BAD_REQUEST, ExceptionCode.USER_NOT_FOUND.name()));
        user.setEnabled(true);
        user.setEmail(user.getUserActivation().getEmail()); 
        user.setUserActivation(null); 
        userRepository.save(user);
    }
public void activate ( ActivateUserSO activateUserSO ) { LOGGER . debug ( "activate({})" , activateUserSO ) ; User user = userRepository . findByUsernameAndUserActivationToken ( activateUserSO . getUsername ( ) , activateUserSO . getToken ( ) ) . orElseThrow ( ( ) -> new ResponseStatusException ( HttpStatus . BAD_REQUEST , ExceptionCode . USER_NOT_FOUND . name ( ) ) ) ; user . setEnabled ( true ) ; user . setEmail ( user . getUserActivation ( ) . getEmail ( ) ) ; user . setUserActivation ( null ) ; userRepository . save ( user ) ; }
activate new user by link from email, set enabled to true
activate new user by link from email set enabled to true
// this is important when user only update email of existing account // remove activation object