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
35 changes: 35 additions & 0 deletions src/main/java/org/launchcode/controllers/UserController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.launchcode.controllers;

import org.launchcode.models.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/user")
public class UserController {

@GetMapping("/add")
public String displayAddUserForm () {
return "/user/add";
}

@PostMapping
public String processAddUserForm(Model model, @ModelAttribute User user, String verify) {
model.addAttribute("user", user);
model.addAttribute("username", user.getUsername());
model.addAttribute("email", user.getEmail());
if (user.getPassword().equals(verify)) {
return "/user/index";
} else {
model.addAttribute("error", "Passwords don't match!");
return "/user/add";
}


}

}
38 changes: 38 additions & 0 deletions src/main/java/org/launchcode/models/User.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package org.launchcode.models;

public class User {

private String username;
private String email;
private String password;

public User(String username, String email, String password) {
this.username = username;
this.email = email;
this.password = password;
}

public String getUsername() {
return username;
}

public void setUsername(String username) {
this.username = username;
}

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}

public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}
}
22 changes: 22 additions & 0 deletions src/main/resources/templates/user/add.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8">
<link href="/static/styles.css" th:href="@{styles.css}" rel="stylesheet" />
<title>Title</title>
</head>
<body>
<form method="post" th:action="@{/user}">
<label for="username">User Name: </label>
<input type="text" id="username" name="username" th:value="${username}">
<label for="password">Password: </label>
<input type="password" id="password" name="password">
<label for="email">Email: </label>
<input type="email" id="email" name="email" th:value="${email}">
<label for="verify">Please verify password: </label>
<input type="password" id="verify" name="verify">
<input type="submit" value="submit">
<h3 th:if="${error}" th:text="${error}"></h3>
</form>
</body>
</html>
12 changes: 12 additions & 0 deletions src/main/resources/templates/user/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8">
<link href="/static/styles.css" th:href="@{styles.css}" rel="stylesheet" />
<title>Title</title>
</head>
<body>
<h1 th:text="'Hello there, '+ ${username}"></h1>
<a th:href="@{/}">Return to home</a>
</body>
</html>