package com.cidic.design.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
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 com.cidic.design.DcController;
import com.cidic.design.exception.DCException;
import com.cidic.design.model.ResultModel;
import com.cidic.design.model.User;
import com.cidic.design.service.UserService;

/**
 * 大赛用户信息处理
 * @author dev
 *
 */
@Controller
@RequestMapping(value="/user")
public class UserController  extends DcController{

	@Autowired
	@Qualifier(value = "userServiceImpl")
	private UserService userServiceImpl;
	
	/**
	 * 用户注册
	 * @param request
	 * @param response
	 * @param user
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="/register", method = RequestMethod.POST)
	public ResultModel registerUser(HttpServletRequest request, HttpServletResponse response,@RequestParam User user){
		resultModel = new ResultModel();
		try{
			userServiceImpl.createUser(user);
			resultModel.setResultCode(200);
			return resultModel;
		}
		catch(Exception e){
			throw new DCException(500, "创建出错");
		}
	}
	
	/**
	 * 用户信息更新
	 * @param request
	 * @param response
	 * @param user
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="/update", method = RequestMethod.POST)
	public ResultModel updateUser(HttpServletRequest request, HttpServletResponse response,@RequestParam User user){
		resultModel = new ResultModel();
		try{
			userServiceImpl.updateUser(user);
			resultModel.setResultCode(200);
			return resultModel;
		}
		catch(Exception e){
			throw new DCException(500, "创建出错");
		}
	}
	
	/**
	 * 用户激活
	 * @param request
	 * @param response
	 * @param email
	 * @param activeCode
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="/active", method = RequestMethod.GET)
	public ResultModel activeUser(HttpServletRequest request, HttpServletResponse response, 
			@RequestParam String email, @RequestParam String activeCode) throws DCException{
		resultModel = new ResultModel();
		userServiceImpl.activeUser(email, activeCode);
		resultModel.setResultCode(200);
		return resultModel;
	}
	
	/**
	 * 找回密码
	 * @param request
	 * @param response
	 * @param email 
	 * @return 500:出错， 300：email不正确， 200:请求成功，请查看邮箱
	 */
	@ResponseBody
	@RequestMapping(value="/findYourPwd", method = RequestMethod.GET)
	public ResultModel findYourPwd(HttpServletRequest request, HttpServletResponse response, @RequestParam String email){
		resultModel = new ResultModel();
		try{
			//userServiceImpl.findByEmail(email);
			resultModel.setResultCode(200);
			return resultModel;
		}
		catch(Exception e){
			throw new DCException(500, "修改出错");
		}
	}
	/**
	 * 修改密码
	 * @param request
	 * @param response
	 * @param newPwd
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="/resetYourPwd", method = RequestMethod.POST)
	public ResultModel resetYourPwd(HttpServletRequest request, HttpServletResponse response, @RequestParam String newPwd){
		resultModel = new ResultModel();
		try{
			resultModel.setResultCode(200);
			return resultModel;
		}
		catch(Exception e){
			throw new DCException(500, "修改出错");
		}
	}
}

@@ -31,16 +31,134 @@
 oller;%0A%0A
+import java.awt.image.RenderedImage;%0Aimport java.io.IOException;%0Aimport java.util.Map;%0A%0Aimport javax.imageio.ImageIO;%0A
 import j
@@ -875,16 +875,59 @@
 Service;
+%0Aimport com.cidic.design.util.GraphicsUtil;
 %0A%0A/**%0A *
@@ -3637,10 +3637,778 @@
 %0A%09%09%7D%0A%09%7D%0A
+%09%0A%09@RequestMapping(value=%22/getCode%22, method = RequestMethod.POST)%0A%09public void getCode(HttpServletRequest request, HttpServletResponse response)%7B%0A%09%09try %7B    %0A%09            %0A%09        response.setHeader(%22Pragma%22,%22No-cache%22);         %0A%09        response.setHeader(%22Cache-Control%22,%22no-cache%22);         %0A%09        response.setDateHeader(%22Expires%22, 0);         %0A%09        //%E8%A1%A8%E6%98%8E%E7%94%9F%E6%88%90%E7%9A%84%E5%93%8D%E5%BA%94%E6%98%AF%E5%9B%BE%E7%89%87         %0A%09        response.setContentType(%22image/jpeg%22);    %0A%09            %0A%09        Map%3CString, Object%3E map=new GraphicsUtil().getGraphics(); %0A%09        request.getSession().setAttribute(%22rand%22, map.get(%22rand%22));    %0A%09        ImageIO.write((RenderedImage)map.get(%22image%22), %22JPEG%22, response.getOutputStream());    %0A%09    %7D catch (IOException e) %7B    %0A%09        e.printStackTrace();    %0A%09    %7D %0A%09%7D%0A
 %7D%0A

fix bug