diff --git a/foxogram-api/src/main/java/su/foxogram/services/UsersService.java b/foxogram-api/src/main/java/su/foxogram/services/UsersService.java index 6643fdc..57f7336 100644 --- a/foxogram-api/src/main/java/su/foxogram/services/UsersService.java +++ b/foxogram-api/src/main/java/su/foxogram/services/UsersService.java @@ -4,6 +4,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataIntegrityViolationException; import org.springframework.stereotype.Service; +import su.foxogram.configs.APIConfig; import su.foxogram.constants.CodesConstants; import su.foxogram.constants.EmailConstants; import su.foxogram.constants.UserConstants; @@ -25,11 +26,14 @@ public class UsersService { private final CodeRepository codeRepository; + private final APIConfig APIConfig; + @Autowired - public UsersService(UserRepository userRepository, EmailService emailService, CodeRepository codeRepository) { + public UsersService(UserRepository userRepository, EmailService emailService, CodeRepository codeRepository, APIConfig APIConfig) { this.userRepository = userRepository; this.emailService = emailService; this.codeRepository = codeRepository; + this.APIConfig = APIConfig; } public User getUser(String username) throws UserNotFoundException { @@ -70,12 +74,14 @@ public void confirmUserDelete(User user, String pathCode) throws CodeIsInvalidEx userRepository.delete(user); log.info("User deleted ({}, {}) successfully", user.getId(), user.getEmail()); - deleteVerificationCode(code); + if (!APIConfig.isDevelopment()) deleteVerificationCode(code); } public Code validateCode(String pathCode) throws CodeIsInvalidException, CodeExpiredException { Code code = codeRepository.findByValue(pathCode); + if (APIConfig.isDevelopment()) return null; + if (code == null) throw new CodeIsInvalidException(); diff --git a/foxogram-common/src/main/java/su/foxogram/services/AuthenticationService.java b/foxogram-common/src/main/java/su/foxogram/services/AuthenticationService.java index 9dfff2c..8774756 100644 --- a/foxogram-common/src/main/java/su/foxogram/services/AuthenticationService.java +++ b/foxogram-common/src/main/java/su/foxogram/services/AuthenticationService.java @@ -7,6 +7,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataIntegrityViolationException; import org.springframework.stereotype.Service; +import su.foxogram.configs.APIConfig; import su.foxogram.constants.CodesConstants; import su.foxogram.constants.EmailConstants; import su.foxogram.constants.UserConstants; @@ -30,12 +31,15 @@ public class AuthenticationService { private final JwtService jwtService; + private final APIConfig APIConfig; + @Autowired - public AuthenticationService(UserRepository userRepository, CodeRepository codeRepository, EmailService emailService, JwtService jwtService) { + public AuthenticationService(UserRepository userRepository, CodeRepository codeRepository, EmailService emailService, JwtService jwtService, APIConfig APIConfig) { this.userRepository = userRepository; this.codeRepository = codeRepository; this.emailService = emailService; this.jwtService = jwtService; + this.APIConfig = APIConfig; } public User getUser(String header, boolean ignoreEmailVerification) throws UserUnauthorizedException, UserEmailNotVerifiedException { @@ -122,12 +126,14 @@ public void verifyEmail(User user, String pathCode) throws CodeIsInvalidExceptio log.info("USER record updated ({}, {}) SET flags to EMAIL_VERIFIED", user.getId(), user.getEmail()); log.info("EMAIL verified for USER ({}, {}) successfully", user.getId(), user.getEmail()); - deleteVerificationCode(code); + if (!APIConfig.isDevelopment()) deleteVerificationCode(code); } public Code validateCode(String pathCode) throws CodeIsInvalidException, CodeExpiredException { Code code = codeRepository.findByValue(pathCode); + if (APIConfig.isDevelopment()) return null; + if (code == null) throw new CodeIsInvalidException();