<repo_name>dbsry267/Oclubis<file_sep>/Oclubis/src/com/oclubis/action/SignoutAction.java
package com.oclubis.action;

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

import com.oclubis.service.UserService;
import com.oclubis.vo.UserVO;


public class SignoutAction implements IAction {

	@Override
	public void excute(HttpServletRequest request, HttpServletResponse response) throws Exception {
		HttpSession session = request.getSession();
		session.invalidate();
		
		RequestDispatcher rd = request.getRequestDispatcher("jsp/oclubis.jsp");
		rd.forward(request, response);
	}
	
}
<file_sep>/Oclubis/src/com/oclubis/vo/CommentVO.java
package com.oclubis.vo;

public class CommentVO {
	private int postnum;
	private String content;
	private String writer;
	private String date;

	public CommentVO() { }

	public CommentVO(int postnum, String content, String writer) {
		super();
		this.postnum = postnum;
		this.content = content;
		this.writer = writer;
	}

	public int getPostnum() {
		return postnum;
	}

	public void setPostnum(int postnum) {
		this.postnum = postnum;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public String getWriter() {
		return writer;
	}

	public void setWriter(String writer) {
		this.writer = writer;
	}

	public String getDate() {
		return date;
	}

	public void setDate(String date) {
		this.date = date;
	}

}
<file_sep>/README.md
# Oclubis
Java 수행 동아리 협업 웹
<file_sep>/Oclubis/src/com/oclubis/action/UpdateuserAction.java
package com.oclubis.action;

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

import com.oclubis.service.UserService;

public class UpdateuserAction implements IAction {

	@Override
	public void excute(HttpServletRequest request, HttpServletResponse response) throws Exception {
		try {
			String act = request.getParameter("button");
			String userid = request.getParameter("check");
			UserService service = new UserService();
			if ("delete".equals(act)) {
				service.deleteUser(userid);
			}
			if ("change".equals(act)) {
				int value = Integer.parseInt(request.getParameter("permissionvalue"));
				service.updatePermission(userid, value);
			}
			RequestDispatcher rd = request.getRequestDispatcher("user.do");
			rd.forward(request, response);
		} catch (Exception e) {
			e.printStackTrace();
			request.setAttribute("error", e.getMessage());
			RequestDispatcher rd = request.getRequestDispatcher("jsp/error.jsp");
			rd.forward(request, response);
		}
	}

}
<file_sep>/Oclubis/src/com/oclubis/action/LikeAction.java
package com.oclubis.action;

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

import com.oclubis.service.PostService;
import com.oclubis.vo.PostVO;
import com.oclubis.vo.UserVO;

public class LikeAction implements IAction {

	@Override
	public void excute(HttpServletRequest request, HttpServletResponse response) throws Exception {
		try {
			// TODO Auto-generated method stub
			String like = request.getParameter("like");
			if (like.equals("dislike")) {
				int num = Integer.parseInt(request.getParameter("number"));
				PostService service = new PostService();
				HttpSession session = request.getSession();
				UserVO user = (UserVO) session.getAttribute("user");
				service.deleteLike(num, user.getName());
				response.sendRedirect("main.do");
			}
			if (like.equals("like")) {
				int num = Integer.parseInt(request.getParameter("number"));
				PostService service = new PostService();
				HttpSession session = request.getSession();
				UserVO user = (UserVO) session.getAttribute("user");
				service.addLike(num, user.getName());
				response.sendRedirect("main.do");
			}
			

		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			request.setAttribute("error", e.getMessage());
			RequestDispatcher rd = request.getRequestDispatcher("jsp/error.jsp");
			rd.forward(request, response);
		}
	}

}
<file_sep>/Oclubis/src/com/oclubis/dao/ReactDao.java
package com.oclubis.dao;

public class ReactDao {

}
<file_sep>/Oclubis/src/com/oclubis/service/UserService.java
package com.oclubis.service;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

import com.oclubis.dao.UserDao;
import com.oclubis.exception.IdOverlapException;
import com.oclubis.vo.UserVO;

public class UserService extends AbstractService {
	public UserVO signin(UserVO user) throws Exception {
		Connection conn = null;
		try {
			conn = getConnection();
			
			UserDao dao = new UserDao(conn);
			
			UserVO vo = dao.searchUser(user);
			
			return vo;
		} finally {
			// TODO: handle finally clause
			if (conn != null) {
				conn.close();
			}
		}
	}

	public void signup(UserVO user) throws Exception {
		Connection conn = null;
		try {
			conn = getConnection();
			
			UserDao dao = new UserDao(conn);
			
			boolean check = dao.searchId(user.getId());
			if (!check) {
				throw new IdOverlapException("중복되는 id가 존재합니다.");
			}
			
			dao.insertUser(user);
			
		} finally {
			if (conn != null) {
				conn.close();
			}
		}
	}

	public List<UserVO> getUserList() throws Exception {
		Connection conn = null;
		try {
			conn = getConnection();
			
			UserDao dao = new UserDao(conn);
			
			List<UserVO> list = dao.getUserList();
			return list;
		} finally {
			if (conn != null) {
				conn.close();
			}
		}
	}

	public void deleteUser(String userid) throws Exception {
		Connection conn = null;
		try {
			conn = getConnection();
			
			UserDao dao = new UserDao(conn);
			
			dao.deleteUser(userid);
			
		} finally {
			// TODO: handle finally clause
			if (conn != null) {
				conn.close();
			}
		}
	}

	public void updatePermission(String userid, int value) throws Exception {
		Connection conn = null;
		try {
			conn = getConnection();
			
			UserDao dao = new UserDao(conn);
			
			dao.updateUserPermission(userid, value);
			
		} finally {
			// TODO: handle finally clause
			if (conn != null) {
				conn.close();
			}
		}
	}
}
<file_sep>/Oclubis/src/com/oclubis/action/SigninAction.java
package com.oclubis.action;

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

import org.apache.commons.lang3.StringUtils;

import com.oclubis.service.UserService;
import com.oclubis.vo.UserVO;

public class SigninAction implements IAction{

	@Override
	public void excute(HttpServletRequest request, HttpServletResponse response) throws Exception {
		try {
			String id = request.getParameter("id");
			String pwd = request.getParameter("pwd");
			validate(id, pwd);
			UserVO user = new UserVO(id, pwd);
			UserService service = new UserService();
			UserVO result = service.signin(user);
			request.setAttribute("user", result);
			request.getSession().setAttribute("user", result);
			RequestDispatcher rd = null;
			if (result.getPermission() == 3) {
//				rd = request.getRequestDispatcher("jsp/admin.jsp");
				response.sendRedirect("jsp/admin.jsp");
			} else {
//				rd = request.getRequestDispatcher("main.do");
				response.sendRedirect("main.do");
			}
//			rd.forward(request, response);
		} catch (Exception e) {
			// TODO: handle exception
			request.setAttribute("error", e.getMessage());
			RequestDispatcher rd = request.getRequestDispatcher("jsp/signin.jsp");
			rd.forward(request, response);
		}
	}
	
	private void validate(String id, String pwd) throws Exception {
		if (StringUtils.isBlank(id))
			throw new Exception("id에 공백이 포함되어있습니다.");
		if (StringUtils.isBlank(pwd))
			throw new Exception("비밀번호에 공백이 포함되어 있습니다.");
	}

}
<file_sep>/Oclubis/src/com/oclubis/vo/ClubVO.java
package com.oclubis.vo;

public class ClubVO {
	private String name;
	private String president;
	private String intro;

	public ClubVO() {}

	public ClubVO(String name, String president) {
		this.name = name;
		this.president = president;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPresident() {
		return president;
	}

	public void setPresident(String president) {
		this.president = president;
	}

	public String getIntro() {
		return intro;
	}

	public void setIntro(String intro) {
		this.intro = intro;
	}

}
<file_sep>/Oclubis/src/com/oclubis/action/SignupAction.java
package com.oclubis.action;

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

import org.apache.commons.lang3.StringUtils;

import com.oclubis.service.UserService;
import com.oclubis.vo.UserVO;

public class SignupAction implements IAction {

	@Override
	public void excute(HttpServletRequest request, HttpServletResponse response) throws Exception {
		try {

			response.setContentType("text/html;charset=utf-8");
			request.setCharacterEncoding("utf-8");

			// 1. 입력값 추출
			String id = request.getParameter("id");
			String pwd = request.getParameter("pwd");
			String name = request.getParameter("name");
			String club = request.getParameter("club");
			System.out.printf("id : %s, pwd : %s, name : %s, club : %s", id, pwd, name, club);
			UserVO user = new UserVO(id, pwd, name, club);
			// 2. 입력값 검증
			validate(user);

			UserService service = new UserService();
			service.signup(user);
			// 회원가입 처리

			RequestDispatcher rd = request.getRequestDispatcher("jsp/signin.jsp");
			rd.forward(request, response);

		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			request.setAttribute("error", e.getMessage());
			RequestDispatcher rd = request.getRequestDispatcher("jsp/signup.jsp");
			rd.forward(request, response);
		}
	}
	
	private void validate(UserVO vo) throws Exception {
		if (StringUtils.isEmpty(vo.getId()))
			throw new Exception("아이디를 입력해주세요");
		if (StringUtils.isEmpty(vo.getPwd()))
			throw new Exception("비밀번호를 입력해주세요");
		if (StringUtils.isEmpty(vo.getName()))
			throw new Exception("이름을 입력해주세요");
		if (StringUtils.isEmpty(vo.getClub()))
			throw new Exception("동아리를 선택해주세요");
	}
}
