Skip to content

Commit

Permalink
Fix ignore code validation on dev
Browse files Browse the repository at this point in the history
  • Loading branch information
nelifs committed Dec 11, 2024
1 parent 0ec922e commit 5a66874
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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();

Expand Down

0 comments on commit 5a66874

Please sign in to comment.