-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Staehler, Michael
committed
Apr 5, 2024
1 parent
1f8678a
commit 7478354
Showing
3 changed files
with
46 additions
and
96 deletions.
There are no files selected for viewing
59 changes: 26 additions & 33 deletions
59
src/main/java/de/fred4jupiter/fredbet/web/validation/ChangePasswordCommandValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,41 @@ | ||
package de.fred4jupiter.fredbet.web.validation; | ||
|
||
import de.fred4jupiter.fredbet.web.profile.ChangePasswordCommand; | ||
import jakarta.validation.ConstraintValidator; | ||
import jakarta.validation.ConstraintValidatorContext; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import de.fred4jupiter.fredbet.web.profile.ChangePasswordCommand; | ||
|
||
/** | ||
* Validates the new password against the password repeat. | ||
* | ||
* @author michael | ||
* | ||
* @author michael | ||
*/ | ||
public class ChangePasswordCommandValidator implements ConstraintValidator<PasswordChangeConstraint, ChangePasswordCommand> { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(ChangePasswordCommandValidator.class); | ||
|
||
@Override | ||
public void initialize(PasswordChangeConstraint passwordChangeConstraint) { | ||
} | ||
|
||
@Override | ||
public boolean isValid(ChangePasswordCommand value, ConstraintValidatorContext context) { | ||
if (value == null) { | ||
return true; | ||
} | ||
|
||
if (!value.getNewPassword().equals(value.getNewPasswordRepeat())) { | ||
context.buildConstraintViolationWithTemplate("{msg.passwordChange.passwordMismatch}") | ||
.addPropertyNode("newPassword").addConstraintViolation().disableDefaultConstraintViolation(); | ||
LOG.error("newPassword and newPasswordRepeat are different"); | ||
return false; | ||
} | ||
|
||
if (value.getOldPassword().equals(value.getNewPassword())) { | ||
context.buildConstraintViolationWithTemplate("{msg.passwordChange.oldAndNewPasswordAreSame}") | ||
.addPropertyNode("newPassword").addConstraintViolation().disableDefaultConstraintViolation(); | ||
LOG.error("newPassword and newPasswordRepeat are different"); | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
private static final Logger LOG = LoggerFactory.getLogger(ChangePasswordCommandValidator.class); | ||
|
||
@Override | ||
public boolean isValid(ChangePasswordCommand value, ConstraintValidatorContext context) { | ||
if (value == null) { | ||
return true; | ||
} | ||
|
||
if (!value.getNewPassword().equals(value.getNewPasswordRepeat())) { | ||
context.buildConstraintViolationWithTemplate("{msg.passwordChange.passwordMismatch}") | ||
.addPropertyNode("newPassword").addConstraintViolation().disableDefaultConstraintViolation(); | ||
LOG.error("newPassword and newPasswordRepeat are different"); | ||
return false; | ||
} | ||
|
||
if (value.getOldPassword().equals(value.getNewPassword())) { | ||
context.buildConstraintViolationWithTemplate("{msg.passwordChange.oldAndNewPasswordAreSame}") | ||
.addPropertyNode("newPassword").addConstraintViolation().disableDefaultConstraintViolation(); | ||
LOG.error("newPassword and newPasswordRepeat are different"); | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
} |
36 changes: 15 additions & 21 deletions
36
src/main/java/de/fred4jupiter/fredbet/web/validation/TeamResultValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,30 @@ | ||
package de.fred4jupiter.fredbet.web.validation; | ||
|
||
import de.fred4jupiter.fredbet.web.matches.MatchResultCommand; | ||
import jakarta.validation.ConstraintValidator; | ||
import jakarta.validation.ConstraintValidatorContext; | ||
|
||
import de.fred4jupiter.fredbet.web.matches.MatchResultCommand; | ||
|
||
/** | ||
* Validator that checks if you enter both goal results. | ||
* | ||
* @author michael | ||
* | ||
* @author michael | ||
*/ | ||
public class TeamResultValidator implements ConstraintValidator<TeamResultConstraint, MatchResultCommand> { | ||
|
||
@Override | ||
public void initialize(TeamResultConstraint constraintAnnotation) { | ||
} | ||
@Override | ||
public boolean isValid(MatchResultCommand value, ConstraintValidatorContext context) { | ||
if (value == null) { | ||
return true; | ||
} | ||
|
||
Integer teamResultOne = value.getTeamResultOne(); | ||
Integer teamResultTwo = value.getTeamResultTwo(); | ||
|
||
@Override | ||
public boolean isValid(MatchResultCommand value, ConstraintValidatorContext context) { | ||
if (value == null) { | ||
return true; | ||
} | ||
if (teamResultOne == null && teamResultTwo == null) { | ||
return true; | ||
} | ||
|
||
Integer teamResultOne = value.getTeamResultOne(); | ||
Integer teamResultTwo = value.getTeamResultTwo(); | ||
|
||
if (teamResultOne == null && teamResultTwo == null) { | ||
return true; | ||
} | ||
|
||
return (teamResultOne != null && teamResultOne >= 0) && (teamResultTwo != null && teamResultTwo >= 0); | ||
} | ||
return (teamResultOne != null && teamResultOne >= 0) && (teamResultTwo != null && teamResultTwo >= 0); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters