|
3 | 3 | import org.springframework.security.access.prepost.PreAuthorize; |
4 | 4 | import org.springframework.stereotype.Controller; |
5 | 5 | import org.springframework.ui.ModelMap; |
| 6 | +import org.springframework.validation.BindingResult; |
6 | 7 | import org.springframework.web.bind.annotation.RequestMapping; |
7 | 8 | import org.springframework.web.bind.annotation.RequestMethod; |
8 | 9 | import org.springframework.web.bind.annotation.RequestParam; |
| 10 | +import org.springframework.web.bind.support.SessionStatus; |
| 11 | +import ru.javawebinar.topjava.LoggedUser; |
| 12 | +import ru.javawebinar.topjava.to.UserTo; |
| 13 | +import ru.javawebinar.topjava.web.user.AbstractUserController; |
| 14 | + |
| 15 | +import javax.validation.Valid; |
9 | 16 |
|
10 | 17 | /** |
11 | 18 | * User: gkislin |
12 | 19 | * Date: 22.08.2014 |
13 | 20 | */ |
14 | 21 | @Controller |
15 | | -public class RootController { |
| 22 | +public class RootController extends AbstractUserController { |
16 | 23 |
|
17 | 24 | @RequestMapping(value = "/", method = RequestMethod.GET) |
18 | 25 | public String root() { |
@@ -40,4 +47,21 @@ public String login(ModelMap model, |
40 | 47 | model.put("message", message); |
41 | 48 | return "login"; |
42 | 49 | } |
| 50 | + |
| 51 | + @RequestMapping(value = "/profile", method = RequestMethod.GET) |
| 52 | + public String profile() { |
| 53 | + return "profile"; |
| 54 | + } |
| 55 | + |
| 56 | + @RequestMapping(value = "/profile", method = RequestMethod.POST) |
| 57 | + public String updateProfile(@Valid UserTo userTo, BindingResult result, SessionStatus status) { |
| 58 | + if (result.hasErrors()) { |
| 59 | + return "profile"; |
| 60 | + } else { |
| 61 | + status.setComplete(); |
| 62 | + LoggedUser.get().update(userTo); |
| 63 | + super.update(userTo); |
| 64 | + return "redirect:meals"; |
| 65 | + } |
| 66 | + } |
43 | 67 | } |
0 commit comments