+ validation
Signed-off-by: Johannes Theiner <j.theiner@live.de>
This commit is contained in:
parent
41d62898c1
commit
5bc0162cf2
6
pom.xml
6
pom.xml
|
@ -146,6 +146,12 @@
|
|||
<version>1.1.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>javax.validation</groupId>
|
||||
<artifactId>validation-api</artifactId>
|
||||
<version>2.0.1.Final</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!--Database-->
|
||||
<dependency>
|
||||
|
|
|
@ -9,6 +9,7 @@ import lombok.Setter;
|
|||
import javax.faces.bean.ManagedBean;
|
||||
import javax.faces.bean.SessionScoped;
|
||||
import javax.faces.context.FacesContext;
|
||||
import javax.validation.constraints.Size;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -41,6 +42,7 @@ public class AddressBean implements Serializable {
|
|||
|
||||
@Getter
|
||||
@Setter
|
||||
@Size(min = 5, max = 5)
|
||||
private Integer zipCode;
|
||||
|
||||
@Getter
|
||||
|
|
|
@ -5,8 +5,12 @@ import de.hsel.itech.db.pojo.User;
|
|||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import javax.faces.application.FacesMessage;
|
||||
import javax.faces.bean.ManagedBean;
|
||||
import javax.faces.bean.SessionScoped;
|
||||
import javax.faces.context.FacesContext;
|
||||
import javax.validation.constraints.Pattern;
|
||||
import javax.validation.constraints.Size;
|
||||
import java.io.Serializable;
|
||||
|
||||
@ManagedBean
|
||||
|
@ -19,10 +23,12 @@ public class UserBean implements Serializable {
|
|||
|
||||
@Getter
|
||||
@Setter
|
||||
@Size(min = 1)
|
||||
private String username;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Pattern(regexp = "(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])")
|
||||
private String email;
|
||||
|
||||
@Getter
|
||||
|
@ -65,6 +71,10 @@ public class UserBean implements Serializable {
|
|||
Database db = Database.getInstance();
|
||||
|
||||
if(username != null && email != null && password != null) {
|
||||
if(db.user().get(username) != null) {
|
||||
FacesContext.getCurrentInstance().addMessage("register:username", new FacesMessage("Dieser Nutzername ist bereits vergeben"));
|
||||
return "register.xhtml";
|
||||
}
|
||||
User user = new User(email, username, password, (short) 1);
|
||||
db.user().insert(user);
|
||||
email = null;
|
||||
|
|
|
@ -11,8 +11,9 @@
|
|||
|
||||
<div class="m-row">
|
||||
<div class="m-col-l-6 m-push-l-4">
|
||||
<h:form>
|
||||
<h:form id="register">
|
||||
<h:inputText id="username" value="#{userBean.username}">Nutzername</h:inputText>
|
||||
<h:message for="username"/>
|
||||
<br/>
|
||||
<h:inputText id="email" value="#{userBean.email}">Email</h:inputText>
|
||||
<br/>
|
||||
|
|
Loading…
Reference in New Issue