
<%	
/************************************************************@@
  * Program Name	: multiCheck.jsp
  * Description		: 로그인
  * Author				: 구경모
  * Create Date		: 2008.1.23
  * History				: 한명의 유저가 여러가지 부서에 속해있을때 확인후 셀렉트를 함.
@@************************************************************/
%>

<%@ page contentType="text/html; charset=UTF-8" import="java.util.Set"
	import="javax.jdo.PersistenceManager" import="javax.jdo.Transaction"
	import="javax.jdo.JDOObjectNotFoundException"
	import="org.jasypt.digest.StandardStringDigester"
	import="org.slf4j.Logger" import="org.slf4j.LoggerFactory"
	import="kr.co.kihyun.moumi.Moumi"
	import="kr.co.kihyun.beans.entity.MUser"
	import="kr.co.kihyun.beans.entity.MDept"
	import="kr.co.kihyun.beans.entity.util.*"
	import="kr.co.kihyun.beans.entity.util.MPersistenceManager"
	import="kr.co.kihyun.beans.user.MultiCheck"
	import="kr.co.kihyun.lang.MString"
	import="kr.co.kihyun.beans.user.User"
	import="kr.co.kihyun.beans.user.HttpSSOLogin"
	import="kr.co.kihyun.lang.Encoder"%>

<%
	request.setCharacterEncoding("UTF-8");
%>

<%
PersistenceManager pm = new MPersistenceManager(PMF.get().getPersistenceManager());
Transaction tx = pm.currentTransaction();
try{
	Logger LOG = LoggerFactory.getLogger(this.getClass());

	String id = MString.checkNull(Encoder.toJava(request.getParameter("id")));
	String password = null;
	MUser mUser = null;
	boolean isLoginSuccess = false;

	password = MString.checkNull(request.getParameter("password"));

	tx.begin();
	mUser = pm.getObjectById(MUser.class, id);
	LOG.debug("mUser.id: {}, mUser.password: {}", new Object[] {mUser.getId(), mUser.getPassword()});


    /*
	LOG.debug("password match: {}", new StandardStringDigester().matches(password, mUser.getPassword()));
	isLoginSuccess = Moumi.getUsePasswdEncrypt()
								&& new StandardStringDigester().matches(password, mUser.getPassword())
								|| mUser.getPassword().equals(password);
	*/
	if(isLoginSuccess) {
		LOG.debug("login success");

%>
<form name="login"
	action="/servlet/kr.co.kihyun.beans.user.HttpSSOLogin" method="post">
<input type="hidden" name="id" value="<%=id%>"> <input
	type="hidden" name="deptID" value="<%=mUser.getUpperDept(pm).getId()%>">
<input type="hidden" name="password" value=<%=password%>></form>

<script>
				login.submit();
			</script>
<%
	}else{
%>
<script>
			alert("비밀번호가 일치하지 않습니다.");
			top.location.href="/index.html";
		</script>
<%
	}
%>

<%
	tx.rollback();
}catch(JDOObjectNotFoundException jonfe){
%>
<script>
		alert("아이디가 존재하지 않습니다.");
		top.location.href="/index.html";
	</script>
<%
}catch(Exception ex){
	ex.printStackTrace();
	out.println(kr.co.kihyun.text.html.ServletUtil.getJavaScript("location='/servlet/kr.co.kihyun.beans.user.HttpSSOLogin?mode=logout';"));
}finally{
	if(tx.isActive())
		tx.rollback();
	pm.close();
}
%>
