Skip to content

Commit

Permalink
rimosso vecchio codice commentato. aggiunte verifiche email in model …
Browse files Browse the repository at this point in the history
…e signin
  • Loading branch information
Kidel committed Jun 12, 2015
1 parent a2cbe64 commit ac7e728
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 11 deletions.
10 changes: 4 additions & 6 deletions src/it/uniroma3/controller/CartController.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public Orders setCartFromId(Long idCustomer) {
this.cart = customerFacade.getCart(idCustomer);
}
catch(Exception e){
//
System.out.println("Error while trying to set controller cart from customer id");
}
return this.cart;
}
Expand All @@ -64,7 +64,7 @@ public String addProductToCart(Orders cart, Product product){
CustomerController cc = new CustomerController();

if(cc.isNotLogged()) {
//return "WEB-INF/errorNotLogged";

this.ch.addErrorMessage("You must be logged to complete this operation");
return "WEB-INF/error";
}
Expand All @@ -81,16 +81,14 @@ public String addProductToCart(Orders cart, Product product){
}
catch(Exception e){
System.out.println("Insufficient Storage Quantity");
//return "WEB-INF/errorQuantity";

this.ch.addErrorMessage("Cart already contains the storage quantity");
return "WEB-INF/error?quantity=-1";
}

}

public String addProductToCartReactive(Orders cart, Product product){
//System.out.println(product.getName());

String output = addProductToCart(cart, product);

if(output.indexOf("quantity") != -1)
Expand All @@ -106,7 +104,7 @@ public String removeOrderLine(Orders cart, OrderLine orderLine){
CustomerController cc = new CustomerController();

if(cc.isNotLogged()) {
//return "WEB-INF/errorNotLogged";

this.ch.addErrorMessage("You must be logged to complete this operation");
return "WEB-INF/error";
}
Expand Down
16 changes: 12 additions & 4 deletions src/it/uniroma3/controller/CustomerController.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,22 @@ public CustomerController() {
}

public String signIn() {
System.out.println("\nAttempting customer signin\n");

if(this.repeatPassword.equals(this.password)){
if(!customerFacade.existsCustomer(this.email)){
Address address = addressFacade.createAddress(street, city, state, zipcode, country);
System.out.println("\nAddress created\n");
this.customer = customerFacade.createCustomer(firstName, lastName, email, password, phoneNumber, dateofBirth, address);
System.out.println("\nCustomer Created\n");

//return "WEB-INF/successSignin";
//if the form is altered and submitted, the validation pattern on the model will prevent
//the customer from being saved on the database. Checking if the customer has been really saved
this.customer = customerFacade.getCustomer(email);
if(this.customer==null) {
this.ch.addMessage("signIn", "email", "There was an error, please try again");
return "signin";
}

System.out.println("\nCustomer persisted\n");
this.ch.addSuccessMessage("Registration successful");
return "WEB-INF/success";
}
Expand All @@ -95,7 +103,7 @@ public String loginCustomer(){
System.out.println("WRONG MAIL OR PASSWORD");

if(page != null && page.contains("WEB-INF")) return "index";
//return "WEB-INF/errorLogin";

this.ch.addErrorMessage("Invalid Email or Password");
return "WEB-INF/error";
}
Expand Down
2 changes: 1 addition & 1 deletion src/it/uniroma3/controller/ProductController.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public String createProduct() {
return "product?id="+this.product.getId()+"&faces-redirect=true&includeViewParams=true";
}
catch (Exception e) {
//return "WEB-INF/errorProduct";

this.ch.addErrorMessage("There was an error");
return "WEB-INF/error";
}
Expand Down
2 changes: 2 additions & 0 deletions src/it/uniroma3/model/Admin.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.Date;

import javax.persistence.*;
import javax.validation.constraints.Pattern;

@Entity
@NamedQuery(name = "findAllAdmins", query = "SELECT a FROM Admin a")
Expand All @@ -19,6 +20,7 @@ public class Admin {
private String lastName;

@Column(unique=true)
@Pattern(regexp = "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$")
private String email;

private String password;
Expand Down
2 changes: 2 additions & 0 deletions src/it/uniroma3/model/Customer.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.List;

import javax.persistence.*;
import javax.validation.constraints.Pattern;

@Entity
@NamedQuery(name = "findAllCustomers", query = "SELECT c FROM Customer c")
Expand All @@ -21,6 +22,7 @@ public class Customer {
private String lastName;

@Column(unique = true)
@Pattern(regexp = "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$")
private String email;

private String password;
Expand Down
3 changes: 3 additions & 0 deletions src/it/uniroma3/model/Provider.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.List;

import javax.persistence.*;
import javax.validation.constraints.Pattern;

@Entity
@NamedQuery(name = "findAllProviders", query = "SELECT pr FROM Provider pr")
Expand All @@ -17,8 +18,10 @@ public class Provider {

private String phoneNumber;

@Pattern(regexp = "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$")
private String email;

@Pattern(regexp = "^[0-9]{11}$", message = "Please insert a valid vatin (11 numbers)")
private String vatin;

@OneToOne(cascade={CascadeType.PERSIST, CascadeType.REMOVE})
Expand Down

0 comments on commit ac7e728

Please sign in to comment.