Skip to content

Commit

Permalink
Sign up: done
Browse files Browse the repository at this point in the history
  • Loading branch information
EdwardAndress committed Jul 25, 2021
1 parent 8845d8d commit 6769b4b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.makersacademy.acebook.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
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;
Expand All @@ -20,20 +21,16 @@ public class UsersController {
AuthoritiesRepository authoritiesRepository;

@GetMapping("/users/new")
public String signup() {
public String signup(Model model) {
model.addAttribute("user", new User());
return "users/new";
}

@PostMapping("/users")
public RedirectView signup(@ModelAttribute User user) {
System.out.println("about to save user");
userRepository.save(user);
System.out.println("user saved");
Authority authority = new Authority(user.getUsername(), "ROLE_USER");
System.out.println("about to save auth");
authoritiesRepository.save(authority);
System.out.println("auth saved");
System.out.println("redirecting");
return new RedirectView("/login");
}
}
6 changes: 3 additions & 3 deletions src/main/java/com/makersacademy/acebook/model/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ public class User {
private String password;
private boolean enabled;

public User() {}
public User() {
this.enabled = TRUE;
}

public User(String username, String password) {
System.out.println("CREATING A USER: 27");
this.username = username;
this.password = password;
this.enabled = TRUE;
}

public User(String username, String password, boolean enabled) {
System.out.println("CREATING A USER: 34");
this.username = username;
this.password = password;
this.enabled = enabled;
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ spring.profiles.active=dev
spring.data.rest.base-path=/api
spring.datasource.platform=postgres
spring.jpa.hibernate.ddl-auto=validate
logging.level.org.springframework.web: DEBUG
25 changes: 12 additions & 13 deletions src/main/resources/templates/users/new.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Signup</title>
</head>
<body>
<form action="/users" method="POST">
<label>Username</label><br>
<input required="true" type="text" name="username"><br>
<label>Password</label><br>
<input required="true" type="password" name="password"><br>
<input type="submit" value="Submit">
</form>
</body>
<head>
<meta charset="UTF-8">
<title>Signup</title>
</head>
<body>
<form action="#" th:action="@{/users}" th:object="${user}" method="post">
<p>Username: <input type="text" th:field="*{username}" /></p>
<p>Password: <input type="password" th:field="*{password}" /></p>
<p><input type="submit" value="Submit" /> <input type="reset" value="Reset" /></p>
</form>
</body>
</html>

0 comments on commit 6769b4b

Please sign in to comment.