generated from Arquisoft/wiq_0
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #92 from Arquisoft/proyectoJava
Add better error handling, email validation, and auto login post signup
- Loading branch information
Showing
5 changed files
with
83 additions
and
16 deletions.
There are no files selected for viewing
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
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
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
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.uniovi.validators; | ||
|
||
import com.uniovi.dto.PlayerDto; | ||
import com.uniovi.services.PlayerService; | ||
import org.apache.commons.validator.routines.EmailValidator; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.validation.Errors; | ||
import org.springframework.validation.Validator; | ||
|
||
@Component | ||
public class SignUpValidator implements Validator { | ||
private PlayerService playerService; | ||
|
||
public SignUpValidator(PlayerService playerService) { | ||
this.playerService = playerService; | ||
} | ||
|
||
@Override | ||
public boolean supports(Class<?> clazz) { | ||
return clazz.equals(PlayerDto.class); | ||
} | ||
|
||
@Override | ||
public void validate(Object target, Errors errors) { | ||
PlayerDto user = (PlayerDto) target; | ||
|
||
if (!EmailValidator.getInstance().isValid(user.getEmail())) { | ||
errors.rejectValue("email", null, | ||
"El email no es válido"); | ||
} | ||
|
||
if(playerService.getUserByEmail(user.getEmail()).isPresent()){ | ||
errors.rejectValue("email", null, | ||
"Ya hay una cuenta registrada con este email"); | ||
} | ||
|
||
if (playerService.getUserByUsername(user.getUsername()).isPresent()) { | ||
errors.rejectValue("username", null, | ||
"Ya existe una cuenta con este nombre de usuario"); | ||
} | ||
|
||
if (user.getPassword() == null | ||
|| !user.getPassword().equals(user.getPasswordConfirm())) { | ||
errors.rejectValue("passwordConfirm", null, | ||
"Las contraseñas no coinciden"); | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -11,16 +11,16 @@ <h2>Registrate</h2> | |
<label class="control-label col-sm-2" for="username">Nombre de usuario:</label> | ||
<div class="col-sm-10"> | ||
<input type="text" class="form-control" id="username" name="username" | ||
placeholder="wikiuser" required="true"/> | ||
placeholder="wikiuser" required="true" th:value="${user.username}"/> | ||
<span class="text-danger" th:if="${#fields.hasErrors('username')}" th:errors="*{username}"></span> | ||
</div> | ||
</div> | ||
<div class="form-group"> | ||
<label class="control-label col-sm-2" for="email">Correo electrónico:</label> | ||
<div class="col-sm-10"> | ||
<input type="text" class="form-control" id="email" name="email" | ||
placeholder="[email protected]" required="true" /> | ||
|
||
placeholder="[email protected]" required="true" th:value="${user.email}"/> | ||
<span class="text-danger" th:if="${#fields.hasErrors('email')}" th:errors="*{email}"></span> | ||
</div> | ||
</div> | ||
<div class="form-group"> | ||
|