package com.cku.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.cku.service.CkuLoginUserServiceImpl;

@Controller
@RequestMapping(value="ckuLoginUser")
public class CkuLoginUserController {
	private static final Logger logger = Logger.getLogger(CkuLoginUserController.class);
	@Autowired
	public CkuLoginUserServiceImpl ckuLoginUserService;
	
	//得到所有接口
	@RequestMapping(value="/login")
	@ResponseBody//结果不会被解析为跳转路径，而是直接写入HTTP response body中
	public void addSign(@RequestParam(value = "userName", required = false)String userName,
			@RequestParam(value = "pwd", required = false)String pwd,
			HttpServletResponse response,HttpServletRequest request) {
		try {
			response.setCharacterEncoding("UTF-8");
			response.setContentType("text/html");
			request.getSession().getAttribute("userId");
			String result = ckuLoginUserService.login(request,userName,pwd);
		    response.getWriter().write(result);
		} catch (Exception e) {
			// TODO: handle exception
			logger.error(e);
		}
	}
}
