error enchere

This commit is contained in:
Parpaillax
2024-04-26 11:28:09 +02:00
parent dd938c52b8
commit b2175b7f96
4 changed files with 18 additions and 7 deletions

View File

@@ -43,7 +43,9 @@ public class EnchereController {
//Empeche une enchere inférieur au prix de base de l'article //Empeche une enchere inférieur au prix de base de l'article
Article article = this.articleService.findArticleById(articleId); Article article = this.articleService.findArticleById(articleId);
if (enchere.getMontantEnchere() < article.getPrixInitial()) { float articlePrice = article.getPrixInitial();
float encherePrice = enchere.getMontantEnchere();
if (encherePrice < articlePrice) {
result.rejectValue("montantEnchere", "error.enchere", "Vous ne pouvez pas enchérir un montant inférieur au prix initial"); result.rejectValue("montantEnchere", "error.enchere", "Vous ne pouvez pas enchérir un montant inférieur au prix initial");
} }
@@ -53,10 +55,14 @@ public class EnchereController {
.map(Enchere::getMontantEnchere) // Récupère seulement les montants d'enchère .map(Enchere::getMontantEnchere) // Récupère seulement les montants d'enchère
.max(Float::compareTo); .max(Float::compareTo);
System.out.println(maxMontantEnchere); System.out.println(maxMontantEnchere);
if (enchere.getMontantEnchere() < maxMontantEnchere.get()) { if (maxMontantEnchere.isPresent() && encherePrice < maxMontantEnchere.get()) {
result.rejectValue("montantEnchere", "error.enchere", "Vous ne pouvez pas enchérir un montant inférieur à la dernière enchère"); result.rejectValue("montantEnchere", "error.enchere", "Vous ne pouvez pas enchérir un montant inférieur à la dernière enchère");
} }
if (result.hasErrors()) {
return "redirect:/article/show?id=" + articleId;
}
this.enchereService.setEnchere(enchere); this.enchereService.setEnchere(enchere);
return "redirect:/article/show?id=" + articleId; return "redirect:/article/show?id=" + articleId;
} }

View File

@@ -125,7 +125,7 @@ public class InscriptionController {
result.rejectValue("password", "error.userProfile", "Les mots de passe ne correspond pas."); result.rejectValue("password", "error.userProfile", "Les mots de passe ne correspond pas.");
} }
// Vérifier si le mot de passe est sécurisé // Vérifier si le mot de passe est sécurisé
String passwordRegex = "^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&+=])(?=\\S+$).{8,}$"; String passwordRegex = "^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[@?*#$%^&+=_!\\-])(?=\\S+$).{8,}$";
Pattern pattern = Pattern.compile(passwordRegex); Pattern pattern = Pattern.compile(passwordRegex);
// Vérifier si le mot de passe correspond à l'expression régulière // Vérifier si le mot de passe correspond à l'expression régulière
if (!pattern.matcher(userProfile.getPassword()).matches()){ if (!pattern.matcher(userProfile.getPassword()).matches()){

View File

@@ -50,6 +50,11 @@
<input type="hidden" id="articleId" name="articleId" th:value="${article.id}"> <input type="hidden" id="articleId" name="articleId" th:value="${article.id}">
<label for="montantEnchere">Montant</label> <label for="montantEnchere">Montant</label>
<input type="number" th:field="*{montantEnchere}" id="montantEnchere" step="0.01" min="0"> <input type="number" th:field="*{montantEnchere}" id="montantEnchere" step="0.01" min="0">
<span style="color: red;" th:if="${#fields.hasErrors('montantEnchere')}">
<ul>
<li th:each="erreur: ${#fields.errors('montantEnchere')}" th:text="${erreur}"></li>
</ul>
</span>
<button type="submit" class="btn btn-primary">Enchérir</button> <button type="submit" class="btn btn-primary">Enchérir</button>
</form> </form>
</div> </div>

View File

@@ -100,10 +100,10 @@
<input type="password" th:field="*{password}" id="password" required/> <input type="password" th:field="*{password}" id="password" required/>
</div> </div>
<span style="color: red;" th:if="${#fields.hasErrors('password')}"> <span style="color: red;" th:if="${#fields.hasErrors('password')}">
<ul> <ul>
<li th:each="erreur: ${#fields.errors('password')}" th:text="${erreur}"></li> <li th:each="erreur: ${#fields.errors('password')}" th:text="${erreur}"></li>
</ul> </ul>
</span> </span>
</div> </div>
<div class="champ-saisie"> <div class="champ-saisie">
<label for="confirmPassword" th:text="#{register.confirm_password.label}">Confirmation du mot de passe: </label> <label for="confirmPassword" th:text="#{register.confirm_password.label}">Confirmation du mot de passe: </label>