package ieven.server.webapp.api; import ieven.server.webapp.domain.user.User; import ieven.server.webapp.infrastructure.wrapper.Mapped; import ieven.server.webapp.service.user.UserService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import javax.servlet.http.HttpSession; @Slf4j @Controller public class UserController { @Autowired UserService userService; /** * 登录账号 * * @param user * @return */ @RequestMapping("user/login") @ResponseBody public Mapped loginAccount(@RequestBody User user, HttpSession session) { User user2 = userService.loginAccount(user); if (user2 != null) { session.setAttribute("loginUser", user); return Mapped.OK(); } return Mapped.ERROR("用户名或者密码错误!"); } @RequestMapping({"alipay", "/"}) public String index() { log.info("index"); return "index.html"; } @RequestMapping("login/out") @ResponseBody public Mapped loginout(HttpSession session) { session.invalidate(); return Mapped.OK(); } }