-
Notifications
You must be signed in to change notification settings - Fork 491
Expand file tree
/
Copy pathUserController.java
More file actions
35 lines (28 loc) · 1.04 KB
/
UserController.java
File metadata and controls
35 lines (28 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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";
}
}
}