diff --git a/src/main/java/org/launchcode/controllers/UserController.java b/src/main/java/org/launchcode/controllers/UserController.java index eacbffbd..f52ae4c1 100644 --- a/src/main/java/org/launchcode/controllers/UserController.java +++ b/src/main/java/org/launchcode/controllers/UserController.java @@ -1,8 +1,10 @@ package org.launchcode.controllers; +import jakarta.validation.Valid; import org.launchcode.models.User; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; +import org.springframework.validation.Errors; import org.springframework.web.bind.annotation.*; @Controller @@ -10,22 +12,23 @@ public class UserController { @GetMapping("/add") - public String displayAddUserForm() { + public String displayAddUserForm(Model model) { + model.addAttribute(new User()); return "user/add"; } @PostMapping - public String processAddUserForm(Model model, @ModelAttribute User user, String verify) { + public String processAddUserForm(Model model, @ModelAttribute @Valid User user,Errors errors, String verify) { model.addAttribute("user", user); - model.addAttribute("verify", verify); - model.addAttribute("username", user.getUsername()); - model.addAttribute("email", user.getEmail()); - if (user.getPassword().equals(verify)) { - return "user/index"; +// model.addAttribute("verify", verify); +// model.addAttribute("username", user.getUsername()); +// model.addAttribute("email", user.getEmail()); + if (errors.hasErrors()) { + return "user/add"; } else { - model.addAttribute("error", "Passwords do not match"); - return "user/add"; +// model.addAttribute("error", "Passwords do not match"); + return "user/index"; } } diff --git a/src/main/java/org/launchcode/models/User.java b/src/main/java/org/launchcode/models/User.java index 29c14fb0..416b48a2 100644 --- a/src/main/java/org/launchcode/models/User.java +++ b/src/main/java/org/launchcode/models/User.java @@ -1,19 +1,37 @@ package org.launchcode.models; +import jakarta.validation.constraints.*; + public class User { + @NotBlank + @Size(min=5, max=15, message = "Username should be 5 to 15 characters long") private String username; + @Email(message = "Email is incorrect") private String email; + @NotBlank + @Size(min = 6, message =" Password should be at least 6 characters long") private String password; + @NotNull(message = "Passwords do not match!") + private String verifyPassword; + public User(){}; + + public String getVerifyPassword() { + return verifyPassword; + } - public User() { + public void setVerifyPassword(String verifyPassword) { + this.verifyPassword = verifyPassword; + checkPassword(); } - public User(String username, String email, String password) { + + public User(String username, String email, String password,String verifyPassword) { this(); this.username = username; this.email = email; this.password = password; + this.verifyPassword=verifyPassword; } public String getUsername() { @@ -38,6 +56,13 @@ public String getPassword() { public void setPassword(String password) { this.password = password; + checkPassword(); } -} - + private void checkPassword() { + if (!(this.password == null) && !(this.verifyPassword == null)) { + if (!(this.password.equals(this.verifyPassword))) { + this.verifyPassword = null; + } + } + } +} \ No newline at end of file diff --git a/src/main/resources/static/styles.css b/src/main/resources/static/css/styles.css similarity index 100% rename from src/main/resources/static/styles.css rename to src/main/resources/static/css/styles.css diff --git a/src/main/resources/templates/menu.html b/src/main/resources/templates/menu.html index f6cefa1f..5fbcb087 100644 --- a/src/main/resources/templates/menu.html +++ b/src/main/resources/templates/menu.html @@ -35,4 +35,4 @@

Pedicure

- \ No newline at end of file + diff --git a/src/main/resources/templates/user/add.html b/src/main/resources/templates/user/add.html index 4d6af86a..24ec010f 100644 --- a/src/main/resources/templates/user/add.html +++ b/src/main/resources/templates/user/add.html @@ -1,35 +1,41 @@ - - - Sign Up + + + Sign Up
- + +

- + - +

-

+ +

- + +

+ + + +
diff --git a/src/main/resources/templates/user/index.html b/src/main/resources/templates/user/index.html index 7852cec1..bf551dc4 100644 --- a/src/main/resources/templates/user/index.html +++ b/src/main/resources/templates/user/index.html @@ -1,14 +1,14 @@ - - - Welcome + + + Welcome

- Select your spa services here + Select your spa services here \ No newline at end of file