Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions src/main/java/org/launchcode/controllers/UserController.java
Original file line number Diff line number Diff line change
@@ -1,31 +1,34 @@
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
@RequestMapping("user")
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";
}

}
Expand Down
33 changes: 29 additions & 4 deletions src/main/java/org/launchcode/models/User.java
Original file line number Diff line number Diff line change
@@ -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() {
Expand All @@ -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;
}
}
}
}
2 changes: 1 addition & 1 deletion src/main/resources/templates/menu.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ <h3>Pedicure</h3>
</div>
</div>
</body>
</html>
</html>
48 changes: 27 additions & 21 deletions src/main/resources/templates/user/add.html
Original file line number Diff line number Diff line change
@@ -1,35 +1,41 @@
<!DOCTYPE html>
<html lang="en" xmlns:th = "http://www.thymeleaf.org/">
<head>
<meta charset="UTF-8">
<link href="../static/css/styles.css" th:href="@{/css/styles.css}" rel="stylesheet" />
<title>Sign Up</title>
<meta charset="UTF-8">
<link href="../static/css/styles.css" th:href="@{/css/styles.css}" rel="stylesheet" />
<title>Sign Up</title>
</head>
<body>
<form method = 'post' th:action="@{/user}">
<label>
Username:
<input type = 'text' name = 'username' th:value="${username}">
</label>
<label>
Username:
<input th:field="${user.username}">

<label>
Email:
<input type = 'email' name = 'email' th:value="${email}">
</label>
</label>
<p class="error" th:errors="${user.username}"></p>

<label>
Password:
<input type = 'password' name = 'password'>
</label>
<label>
Email:
<input th:field="${user.email}">
</label>

<label>
Verify Password:
<input type = 'password' name = 'verify'>
</label>
<p class="error" th:errors="${user.email}"></p>

<p th:text="${error}"></p>
<label>
Password:
<input type = 'password' th:field="${user.password}">
</label>
<p class="error" th:errors="${user.password}"></p>

<input type = 'submit' value = 'Sign Up'>
<label>
Verify Password:
<input type = 'password' th:field="${user.verifyPassword}">
</label>
<p class="error" th:errors="${user.verifyPassword}"></p>



<input type = 'submit' value = 'Sign Up'>
</form>

</body>
Expand Down
8 changes: 4 additions & 4 deletions src/main/resources/templates/user/index.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<!DOCTYPE html>
<html lang="en" xmlns:th = "http://www.thymeleaf.org/">
<head>
<meta charset="UTF-8">
<link href="../static/css/styles.css" th:href="@{/css/styles.css}" rel="stylesheet" />
<title>Welcome</title>
<meta charset="UTF-8">
<link href="../static/css/styles.css" th:href="@{/css/styles.css}" rel="stylesheet" />
<title>Welcome</title>
</head>
<body>
<p th:text = "'Welcome ' + ${user.username} + '!'"></p>
<a th:href="@{/}">
Select your spa services here
Select your spa services here
</a>
</body>
</html>