|
@@ -0,0 +1,109 @@
|
|
|
|
|
+package com.runzhixing.servlet;
|
|
|
|
|
+
|
|
|
|
|
+import java.io.IOException;
|
|
|
|
|
+import java.io.InputStreamReader;
|
|
|
|
|
+import java.io.PrintWriter;
|
|
|
|
|
+import java.util.HashMap;
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
+
|
|
|
|
|
+import javax.servlet.ServletException;
|
|
|
|
|
+import javax.servlet.http.HttpServlet;
|
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
+
|
|
|
|
|
+import org.apache.commons.lang3.ObjectUtils;
|
|
|
|
|
+
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
+import com.runzhixing.bean.User;
|
|
|
|
|
+import com.runzhixing.constant.Constant;
|
|
|
|
|
+import com.runzhixing.packageProcedure.LoginProcedure;
|
|
|
|
|
+import com.runzhixing.tool.JsonUtil;
|
|
|
|
|
+import com.runzhixing.tool.Security;
|
|
|
|
|
+import com.runzhixing.tool.Tool;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * 绑定密码验证
|
|
|
|
|
+ * @author it5
|
|
|
|
|
+ *
|
|
|
|
|
+ */
|
|
|
|
|
+public class PasswordVerifyServlet extends HttpServlet {
|
|
|
|
|
+
|
|
|
|
|
+ private static final long serialVersionUID = -882284019225266182L;
|
|
|
|
|
+
|
|
|
|
|
+ public void doGet(HttpServletRequest request, HttpServletResponse response)
|
|
|
|
|
+ throws ServletException, IOException {
|
|
|
|
|
+ response.setContentType("text/html");
|
|
|
|
|
+ PrintWriter out = response.getWriter();
|
|
|
|
|
+ out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
|
|
|
|
|
+ out.println("<HTML>");
|
|
|
|
|
+ out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
|
|
|
|
|
+ out.println(" <BODY>");
|
|
|
|
|
+ out.print(" This is ");
|
|
|
|
|
+ out.print(this.getClass());
|
|
|
|
|
+ out.println(", using the GET method");
|
|
|
|
|
+ out.println(" </BODY>");
|
|
|
|
|
+ out.println("</HTML>");
|
|
|
|
|
+ out.flush();
|
|
|
|
|
+ out.close();
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public void doPost(HttpServletRequest request, HttpServletResponse response)
|
|
|
|
|
+ throws ServletException, IOException {
|
|
|
|
|
+ String bindUserId = request.getParameter("bindUserId");
|
|
|
|
|
+ String bindUserPwd = request.getParameter("bindUserPwd");
|
|
|
|
|
+ String modal = request.getParameter("modal");
|
|
|
|
|
+ if (Tool.isNullOrEmpty(modal)) {
|
|
|
|
|
+ modal = "1";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Map<String,Object> map=new HashMap<String, Object>();
|
|
|
|
|
+ response.setCharacterEncoding("utf-8");
|
|
|
|
|
+ response.setContentType("text/html;charset=utf-8");
|
|
|
|
|
+ User user = new User();
|
|
|
|
|
+ String loginResult = "";
|
|
|
|
|
+ String code = "0";
|
|
|
|
|
+ String result = "fail";
|
|
|
|
|
+ if( !Tool.isNullOrEmpty(bindUserId) &&!Tool.isNullOrEmpty(bindUserPwd)){
|
|
|
|
|
+ user = new LoginProcedure().login(bindUserId, Security.md5(bindUserPwd), modal);
|
|
|
|
|
+ loginResult = user.getLoginInfo().trim();
|
|
|
|
|
+ if(Constant.loginResult.equals(loginResult)&&user.isValidUser()){
|
|
|
|
|
+ code = "1";
|
|
|
|
|
+ result = "success";
|
|
|
|
|
+ }
|
|
|
|
|
+ }else {
|
|
|
|
|
+ JSONObject json = requestToJsonString(request);
|
|
|
|
|
+ if (ObjectUtils.isNotEmpty(json)) {
|
|
|
|
|
+ bindUserId = json.getString("bindUserId");
|
|
|
|
|
+ bindUserPwd = json.getString("bindUserPwd");
|
|
|
|
|
+ if (!Tool.isNullOrEmpty(json.getString("modal"))) {
|
|
|
|
|
+ modal = json.getString("modal");
|
|
|
|
|
+ }
|
|
|
|
|
+ if( !Tool.isNullOrEmpty(bindUserId) &&!Tool.isNullOrEmpty(bindUserPwd)){
|
|
|
|
|
+ user = new LoginProcedure().login(bindUserId, Security.md5(bindUserPwd), modal);
|
|
|
|
|
+ loginResult = user.getLoginInfo().trim();
|
|
|
|
|
+ if(Constant.loginResult.equals(loginResult)&&user.isValidUser()){
|
|
|
|
|
+ code = "1";
|
|
|
|
|
+ result = "success";
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ map.put("code", code);
|
|
|
|
|
+ map.put("result", result);
|
|
|
|
|
+ JsonUtil.outjson(map, response, null, JsonUtil.df, "");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ public JSONObject requestToJsonString(HttpServletRequest request) throws IOException {
|
|
|
|
|
+ InputStreamReader isr = new InputStreamReader(request.getInputStream(),"utf-8");
|
|
|
|
|
+ String result = "";
|
|
|
|
|
+ int respInt = isr.read();
|
|
|
|
|
+ while(respInt!=-1) {
|
|
|
|
|
+ result +=(char)respInt;
|
|
|
|
|
+ respInt = isr.read();
|
|
|
|
|
+ }
|
|
|
|
|
+ JSONObject jsonResult = JSONObject.parseObject(result);
|
|
|
|
|
+ return jsonResult;
|
|
|
|
|
+ }
|
|
|
|
|
+}
|