<%@page import="user.User"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import ="user.UserDAO" %>
<%@ page import ="java.io.PrintWriter" %>
<% request.setCharacterEncoding("UTF-8"); %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>DoubleSS</title>
</head>
<body>
	<%
		String ID = null;
		UserDAO userDAO = new UserDAO();
		ID = request.getParameter("ID");
		
		String password = request.getParameter("password");
		int passCheckNum = userDAO.login(ID, password);
		System.out.println(passCheckNum+ID);
		if(passCheckNum != 1){
			PrintWriter script = response.getWriter();
			script.println("<script>");
			script.println("alert( '비밀번호가 틀립니다..')");
			script.println("history.back()");
			script.println("</script>");
		}
		
		String newpassword = request.getParameter("newpassword");
		String renewpassword = request.getParameter("renewpassword");
		if(newpassword.equals(renewpassword)){
			
		}else{
			PrintWriter script = response.getWriter();
			script.println("<script>");
			script.println("alert( '변경할 비밀번호가 다릅니다..')");
			script.println("history.back()");
			script.println("</script>");
		}
		String name = request.getParameter("name");
		String email = request.getParameter("email");
		String phone_number = request.getParameter("pnum1") + request.getParameter("pnum2") + request.getParameter("pnum3");
		int postnum = Integer.parseInt(request.getParameter("postnum"));
		String address = request.getParameter("address");
		String d_address =request.getParameter("d_address");
		
		System.out.println(newpassword+name+phone_number+postnum+address+d_address);
		
		if(newpassword == null || name == null || email == null
				|| phone_number == null || request.getParameter("postnum") == null || address == null || d_address == null){
			PrintWriter script = response.getWriter();
			script.println("<script>");
			script.println("alert( '입력이 안된 사항이 있습니다.')");
			script.println("history.back()");
			script.println("</script>");
		} else{
			int result = userDAO.update(newpassword, name, postnum, address, d_address, phone_number, email, ID); //아이디ㄱ 패스워드 넘기기
			if(result == -1){	//이미 존재하는 아이디
				PrintWriter script = response.getWriter();
				script.println("<script>");
				script.println("alert('이미 존재하는 아이디입니다.')");
				script.println("history.back()");
				script.println("</script>");
			}else {
				session.setAttribute("userID", ID);
				PrintWriter script = response.getWriter();
				script.println("<script>");
				script.println("location.href = 'main.jsp'");
				script.println("</script>");
			}
		}
	%>
</body>
</html>