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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
| import javax.inject.Inject; import javax.servlet.http.HttpSession;
import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import com.bestpricemarket.domain.MemberVO; import com.bestpricemarket.service.MemberService;
@Controller @RequestMapping(value = "/member/*") public class MemberController {
@Inject private MemberService service; private static final Logger l = LoggerFactory.getLogger(MemberController.class); @RequestMapping(value = "/join", method = RequestMethod.GET) public String insertGET() throws Exception { return "/member/loginandjoin"; } @RequestMapping(value = "/join", method = RequestMethod.POST) public String insertPOST(MemberVO vo) throws Exception{ l.info("C: 회원가입포스트메서드"+ vo); service.joinMember(vo); return "redirect:/member/login"; } @RequestMapping(value = "/idCheck", method = RequestMethod.POST) public @ResponseBody int idCheck(@RequestParam("id") String id) throws Exception { MemberVO ck = service.idCheck(id); if(ck != null) return 1; else return 0; } @RequestMapping(value = "/login", method = RequestMethod.GET) public String loginGET() throws Exception{ return "/member/loginandjoin"; } @RequestMapping(value = "/login", method = RequestMethod.POST) public String loginPOST(MemberVO vo, HttpSession session, RedirectAttributes rttr) throws Exception{ MemberVO returnVO = service.loginMember(vo); System.out.println("C: 리턴VO결과(서비스에서 예외처리를 진행했으므로 null이 출력되면 코드에 문제있다는 의미) "+returnVO); if(returnVO != null) { session.setAttribute("id", returnVO.getId()); rttr.addFlashAttribute("mvo", returnVO); return "redirect:/member/main"; } else { return "redirect:/member/login"; } } @RequestMapping(value = "/logout", method = RequestMethod.GET) public void logoutGET(HttpSession session) throws Exception{ l.info("C: 로그아웃 GET"); session.invalidate(); } @ResponseBody @RequestMapping(value = "/loginGoogle", method = RequestMethod.POST) public String loginGooglePOST(MemberVO vo, HttpSession session, RedirectAttributes rttr, MemberVO mvo) throws Exception{ MemberVO returnVO = service.loginMemberByGoogle(vo); String mvo_ajaxid = mvo.getId(); System.out.println("C: 구글아이디 포스트 db에서 가져온 vo "+ vo); System.out.println("C: 구글아이디 포스트 ajax에서 가져온 id "+ mvo_ajaxid); if(returnVO == null) { service.joinMemberByGoogle(vo); returnVO = service.loginMemberByGoogle(vo); session.setAttribute("id", returnVO.getId()); rttr.addFlashAttribute("mvo", returnVO); } if(mvo_ajaxid.equals(returnVO.getId())){ service.loginMemberByGoogle(vo); session.setAttribute("id", returnVO.getId()); rttr.addFlashAttribute("mvo", returnVO); }else { service.joinMemberByGoogle(vo); returnVO = service.loginMemberByGoogle(vo); session.setAttribute("id", returnVO.getId()); rttr.addFlashAttribute("mvo", returnVO); } return "redirect:/member/main"; }
|