250 lines
7.9 KiB
Plaintext
250 lines
7.9 KiB
Plaintext
package th.co.muangthai.endrprint.controller;
|
|
|
|
import org.apache.log4j.Logger;
|
|
import org.hibernate.cfg.Configuration;
|
|
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.ResponseBody;
|
|
import th.co.muangthai.endrprint.controller.service.LoginService;
|
|
import th.co.muangthai.endrprint.model.bean.form.*;
|
|
import th.co.muangthai.endrprint.model.bean.form.master.EndrUserLoginForm;
|
|
import th.co.muangthai.endrprint.model.bean.master.EndrUserLoginBean;
|
|
import th.co.muangthai.endrprint.model.wfservice.MTLGetUrlService;
|
|
import th.co.muangthai.endrprint.model.wfservice.SearchPolicyDetailProxyService;
|
|
import th.co.muangthai.endrprint.util.SessionUtil;
|
|
import th.co.muangthai.endrprint.util.TextContent;
|
|
import th.co.muangthai.endrprint.util.VSMUtil;
|
|
|
|
import javax.servlet.ServletException;
|
|
import javax.servlet.http.Cookie;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import java.io.IOException;
|
|
import java.net.Inet4Address;
|
|
import java.net.InetAddress;
|
|
import java.net.NetworkInterface;
|
|
import java.net.SocketException;
|
|
import java.util.*;
|
|
|
|
/**
|
|
* Login management
|
|
*/
|
|
@Controller
|
|
public class LoginController extends AbstractMasterController {
|
|
private Logger log = Logger.getLogger(LoginController.class);
|
|
|
|
/**
|
|
* Check Login
|
|
*
|
|
* @param request
|
|
* @return Object[]
|
|
*/
|
|
@RequestMapping(value = "/LoginJsonController", method = RequestMethod.POST)
|
|
public
|
|
@ResponseBody
|
|
Object[] searchGetLogin(HttpServletRequest request) {
|
|
Object[] obj = new Object[2];
|
|
try {
|
|
|
|
log.info("LoginJsonController { ");
|
|
|
|
//รับค่าจาก page
|
|
String user = request.getParameter("user");
|
|
//แปลงค่าจาก เป็น Bean,List
|
|
EndrUserLoginForm userBeans = mapper.readValue(user, EndrUserLoginForm.class);
|
|
|
|
LoginService loginService = new LoginService();
|
|
|
|
EndrUserLoginForm loginBean = new EndrUserLoginForm();
|
|
loginBean.setUserId(userBeans.getUserId());
|
|
loginBean.setUserPassword(userBeans.getUserPassword());
|
|
EndrUserLoginForm userLogin = loginService.autherizeUser(loginBean);
|
|
|
|
obj[0] = userLogin;
|
|
obj[1] = SessionUtil.getSession().getAttribute("dv");
|
|
|
|
log.info("LoginJsonController }");
|
|
log.info("Login Id : " + obj[0]);
|
|
return obj;//toStringJson(gsonData.toJson(obj));
|
|
} catch (Exception ex) {
|
|
log.error(ex.toString(), ex);
|
|
obj[0] = new EndrUserLoginForm();
|
|
}
|
|
return obj;
|
|
}
|
|
|
|
/**
|
|
* Check Login
|
|
*
|
|
* @param request
|
|
* @return Object[]
|
|
*/
|
|
@RequestMapping(value = "/json/doCheckLogin", method = RequestMethod.POST)
|
|
public
|
|
@ResponseBody
|
|
Object[] doCheckLogin(HttpServletRequest request) {
|
|
Object[] obj = new Object[1];
|
|
try {
|
|
obj[0] = SessionUtil.getSession().getAttribute("dv");
|
|
return obj;//toStringJson(gsonData.toJson(obj));
|
|
} catch (Exception ex) {
|
|
log.error(ex.toString(), ex);
|
|
obj[0] = new EndrUserLoginForm();
|
|
}
|
|
return obj;
|
|
}
|
|
|
|
/**
|
|
* get session
|
|
*
|
|
* @param request
|
|
* @return Object[]
|
|
*/
|
|
@RequestMapping(value = "/json/getSessionLogin", method = RequestMethod.POST)
|
|
public
|
|
@ResponseBody
|
|
Object[] getSessionLogin(HttpServletRequest request) {
|
|
Object[] obj = new Object[4];
|
|
try {
|
|
|
|
log.info("getSessionLogin {");
|
|
EndrUserLoginBean loginForm = SessionUtil.getUserLoginForm();
|
|
|
|
if (null != loginForm && null != loginForm.getUserId()) {
|
|
|
|
//check admin
|
|
EndrUserLoginForm user = commonService.searchUserLoginBeanByUserId(loginForm.getUserId(), null);
|
|
|
|
|
|
obj[0] = loginForm;
|
|
obj[1] = TextContent.DEPLOYMENT_VERSION;
|
|
obj[2] = "anupong".equals(loginForm.getUserId()) ? true : false;
|
|
obj[3] = user.getDepcode();
|
|
|
|
log.info("getSessionLogin }");
|
|
return obj;
|
|
}
|
|
|
|
obj[0] = 1;
|
|
|
|
} catch (Exception ex) {
|
|
log.error(ex.toString(), ex);
|
|
obj[0] = 2;
|
|
//ex.printStackTrace();
|
|
}
|
|
return obj;
|
|
}
|
|
|
|
/**
|
|
* logout clearSession
|
|
*
|
|
* @param request
|
|
*/
|
|
@RequestMapping(value = "/logoutJsonController", method = RequestMethod.POST)
|
|
public void logout(HttpServletRequest request) {
|
|
try {
|
|
log.info("logoutJsonController");
|
|
VSMUtil.SystemPrintDebugMode("........................... {");
|
|
|
|
//Clear Session
|
|
clearSession(request);
|
|
|
|
|
|
VSMUtil.SystemPrintDebugMode("........................... }");
|
|
} catch (Exception ex) {
|
|
log.error(ex.toString(), ex);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Get Cookie
|
|
*
|
|
* @param request
|
|
* @param response
|
|
* @param ipAddress
|
|
* @return String
|
|
* @throws IOException
|
|
* @throws ServletException
|
|
*/
|
|
@RequestMapping(value = "/getCookieController", method = RequestMethod.POST)
|
|
public
|
|
@ResponseBody
|
|
String doGetCookie(HttpServletRequest request, HttpServletResponse response, String ipAddress)
|
|
throws IOException, ServletException {
|
|
String color = null;
|
|
|
|
try {
|
|
|
|
String classId = request.getParameter("classId");
|
|
String flag = request.getParameter("flag");
|
|
|
|
Cookie[] cookies = request.getCookies();
|
|
boolean foundCookie = false;
|
|
|
|
for (int i = 0; i < cookies.length; i++) {
|
|
Cookie cookie1 = cookies[i];
|
|
if (cookie1.getName().equals("color")) {
|
|
color = cookie1.getValue();
|
|
//log.info("bgcolor = " + cookie1.getValue());
|
|
//log.info("ip = " + cookie1.getValue());
|
|
foundCookie = true;
|
|
} else if (cookie1.getName().equals("ip")) {
|
|
//log.info("ip = " + cookie1.getValue());
|
|
foundCookie = true;
|
|
}
|
|
|
|
}
|
|
|
|
if (VSMUtil.isNotEmpty(ipAddress)) {
|
|
if (flag.equals("1")) {
|
|
Cookie cookie1 = new Cookie("color", VSMUtil.isNotEmpty(classId) ? classId : "pink");
|
|
cookie1.setMaxAge(24 * 60 * 60);
|
|
response.addCookie(cookie1);
|
|
}
|
|
|
|
if (!foundCookie) {
|
|
Cookie cookie2 = new Cookie("ip", ipAddress);
|
|
cookie2.setMaxAge(24 * 60 * 60);
|
|
response.addCookie(cookie2);
|
|
}
|
|
}
|
|
|
|
} catch (Exception ex) {
|
|
|
|
}
|
|
return color;
|
|
}
|
|
|
|
|
|
/**
|
|
* logout clearSession
|
|
*
|
|
* @param request
|
|
*/
|
|
@RequestMapping(value = "/callProcessWFMT", method = RequestMethod.POST)
|
|
public
|
|
@ResponseBody
|
|
Object[] doCallProcessWFMT(HttpServletRequest request) {
|
|
String applicationNo = "", url = "";
|
|
try {
|
|
String policyNo = request.getParameter("policyNoParam");
|
|
String documentType = request.getParameter("documentTypeParam");
|
|
if (VSMUtil.isNotEmpty(policyNo)) {
|
|
SearchPolicyDetailProxyService wfService = new SearchPolicyDetailProxyService();
|
|
applicationNo = wfService.querySearchPolicyDetail(policyNo);
|
|
|
|
if (VSMUtil.isNotEmpty(applicationNo)) {
|
|
MTLGetUrlService getUrlService = new MTLGetUrlService();
|
|
url = getUrlService.querySearchPolicyDetail(applicationNo, documentType);
|
|
}
|
|
} else {
|
|
|
|
}
|
|
} catch (Exception ex) {
|
|
// log.error(ex.toString(), ex);
|
|
}
|
|
|
|
return new Object[]{applicationNo, url};
|
|
}
|
|
} |