Skip to content

Commit

Permalink
refactor: 컨트롤러 통합
Browse files Browse the repository at this point in the history
  • Loading branch information
kevstevie committed Sep 25, 2023
1 parent 9106e3c commit 116a9d7
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 49 deletions.
17 changes: 14 additions & 3 deletions app/src/main/java/com/techcourse/controller/LoginController.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,22 @@
public class LoginController {

private static final Logger log = LoggerFactory.getLogger(LoginController.class);
private static final String REDIRECT_INDEX_JSP = "redirect:/index.jsp";

@RequestMapping(value = "/login", method = RequestMethod.GET)
public ModelAndView loginView(final HttpServletRequest req, final HttpServletResponse res) {
return UserSession.getUserFrom(req.getSession())
.map(user -> {
log.info("logged in {}", user.getAccount());
return new ModelAndView(new JspView(REDIRECT_INDEX_JSP));
})
.orElse(new ModelAndView(new JspView("/login.jsp")));
}

@RequestMapping(value = "/login", method = RequestMethod.POST)
public ModelAndView execute(final HttpServletRequest req, final HttpServletResponse res) {
public ModelAndView login(final HttpServletRequest req, final HttpServletResponse res) {
if (UserSession.isLoggedIn(req.getSession())) {
return new ModelAndView(new JspView("redirect:/index.jsp"));
return new ModelAndView(new JspView(REDIRECT_INDEX_JSP));
}

return InMemoryUserRepository.findByAccount(req.getParameter("account"))
Expand All @@ -35,7 +46,7 @@ private ModelAndView login(final HttpServletRequest request, final User user) {
if (user.checkPassword(request.getParameter("password"))) {
final var session = request.getSession();
session.setAttribute(UserSession.SESSION_KEY, user);
return new ModelAndView(new JspView("redirect:/index.jsp"));
return new ModelAndView(new JspView(REDIRECT_INDEX_JSP));
}
return new ModelAndView(new JspView("redirect:/401.jsp"));
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
public class RegisterController {

@RequestMapping(value = "/register", method = RequestMethod.POST)
public ModelAndView execute(final HttpServletRequest req, final HttpServletResponse res) {
public ModelAndView register(final HttpServletRequest req, final HttpServletResponse res) {
final var user = new User(2,
req.getParameter("account"),
req.getParameter("password"),
Expand All @@ -23,4 +23,9 @@ public ModelAndView execute(final HttpServletRequest req, final HttpServletRespo

return new ModelAndView(new JspView("/index.jsp"));
}

@RequestMapping(value = "/register", method = RequestMethod.GET)
public ModelAndView registerView(final HttpServletRequest req, final HttpServletResponse res) {
return new ModelAndView(new JspView("/register.jsp"));
}
}

This file was deleted.

0 comments on commit 116a9d7

Please sign in to comment.