package idc.board.command;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import idc.model.IdcDAO;
import idc.model.IdcMemberDBDTO;

public class BoardWriteCmd implements BoardCmd
{
	private IdcDAO dao = new IdcDAO();
	public void execute(HttpServletRequest request, HttpServletResponse response)
	{
		//checkToken 값이 다르면 true반환.
		if(dao.checkToken(request))
		{
			request.setAttribute("reError", dao.reError);
			return;
		}
		else
		{
			//토큰이 같아서 등록성공이 될 경우 토큰을 삭제해 준다.
			request.getSession().removeAttribute("token");
		}		

		//String name = request.getParameter("name");
		IdcMemberDBDTO d1to = (IdcMemberDBDTO)request.getSession().getAttribute("member");
		String name = d1to.getName();
				
		String subject = request.getParameter("subject");
		String content = request.getParameter("content");
		String password = request.getParameter("password");
		
		BoardDAO dao = new BoardDAO();
		dao.boardWrite(name, subject, content, password);
		
	}

}
