//
|
// Source code recreated from a .class file by IntelliJ IDEA
|
// (powered by Fernflower decompiler)
|
//
|
|
package com.javen.controller;
|
|
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSONObject;
|
import com.javen.common.ApplicationConfig;
|
import com.javen.common.Des1;
|
import com.javen.common.HttpRequest;
|
|
import java.io.IOException;
|
import java.util.HashMap;
|
import java.util.Map;
|
|
import com.javen.common.VerifyCodeUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Controller;
|
import org.springframework.ui.Model;
|
import org.springframework.util.StringUtils;
|
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMethod;
|
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpSession;
|
|
@Controller
|
@RequestMapping({"/"})
|
public class PublishController {
|
@Autowired
|
private ApplicationConfig app = null;
|
private String password = "";
|
|
public PublishController() {
|
}
|
|
@RequestMapping(
|
value = {"/{tenantID}/{formID}"},
|
method = {RequestMethod.GET}
|
)
|
public String showForm(@PathVariable String tenantID, @PathVariable String formID, @RequestParam(required = false) String preview, Model model) {
|
String tokenUrl = this.app.server + this.app.authUrl;
|
String formDatabaseUrl = this.app.server + this.app.datasourceUrl;
|
String formInterfaceUrl = this.app.server + this.app.interfaceUrl;
|
String formEventUrl = this.app.server + this.app.eventUrl;
|
String formResourceUrl = this.app.server + this.app.resourceUrl;
|
String apiUrl = this.app.server + this.app.apiUrl;
|
String requirepasswordUrl = this.app.server + this.app.publishPasswordUrl;
|
if (StringUtils.isEmpty(preview)) {
|
preview = "3";
|
}
|
|
String param = "formID=" + formID + "&tenantID=" + tenantID;
|
model.addAttribute("formID", formID);
|
model.addAttribute("tenantID", tenantID);
|
model.addAttribute("preview", preview);
|
JSONObject postParam = new JSONObject();
|
postParam.put("username", this.app.publicUser);
|
postParam.put("password", this.app.publicPassword);
|
String resultToken = HttpRequest.post(tokenUrl, postParam);
|
Map<String, Object> mapToken = JSON.parseObject(resultToken);
|
String token = mapToken.get("token").toString();
|
model.addAttribute("accessToken", token);
|
model.addAttribute("userName", this.app.publicUser);
|
String resultPassword = HttpRequest.get(requirepasswordUrl, param, token);
|
Map<String, Object> mapPassword = JSON.parseObject(resultPassword);
|
Map<String, Object> mapResult = null;
|
if (mapPassword == null) {
|
mapResult = new HashMap();
|
((Map)mapResult).put("accesspassword", "");
|
((Map)mapResult).put("requirepassword", "0");
|
} else {
|
mapResult = new HashMap();
|
if (mapPassword.get("data").toString().equals("{}")) {
|
((Map)mapResult).put("accesspassword", "");
|
((Map)mapResult).put("requirepassword", "0");
|
} else {
|
mapResult = JSON.parseObject(mapPassword.get("data").toString());
|
}
|
}
|
|
if (((Map)mapResult).get("accesspassword") == null) {
|
this.password = "";
|
} else {
|
this.password = ((Map)mapResult).get("accesspassword").toString();
|
}
|
|
if (((Map)mapResult).get("requirepassword") == null) {
|
model.addAttribute("requirepassword", 0);
|
} else {
|
model.addAttribute("requirepassword", ((Map)mapResult).get("requirepassword"));
|
}
|
|
String resultDatabase = HttpRequest.get(formDatabaseUrl, param, token);
|
Map<String, Object> mapDatabase = JSON.parseObject(resultDatabase);
|
model.addAttribute("formdatabase", mapDatabase.get("data").toString());
|
String resultInterface = HttpRequest.get(formInterfaceUrl, param, token);
|
Map<String, Object> mapInterface = JSON.parseObject(resultInterface);
|
model.addAttribute("forminterface", mapInterface.get("data"));
|
String resultEvent = HttpRequest.get(formEventUrl, param, token);
|
Map<String, Object> mapEvent = JSON.parseObject(resultEvent);
|
model.addAttribute("formevent", mapEvent.get("data"));
|
String resultResource = HttpRequest.get(formResourceUrl, param, token);
|
String resource = "";
|
if ("".equals(resultResource)) {
|
resource = "";
|
} else {
|
Map<String, Object> mapResource = JSON.parseObject(resultResource);
|
resource = mapResource.get("data").toString();
|
}
|
|
model.addAttribute("formresource", resource);
|
String resultApi = HttpRequest.get(apiUrl, param, token);
|
Map<String, Object> mapApi = JSON.parseObject(resultApi);
|
model.addAttribute("formapi", mapApi.get("data"));
|
return "showForm";
|
}
|
|
@RequestMapping(
|
value = {"auth"},
|
method = {RequestMethod.POST}
|
)
|
@ResponseBody
|
public String authPassword(String ver,String accesspassword, HttpServletRequest request) {
|
HttpSession session = request.getSession(true);
|
String verSession = String.valueOf(session.getAttribute("verCode"));
|
if(!Des1.desDecrypt(ver,"").equals(verSession)){
|
// return Des1.desDecrypt(ver,"")+"-----"+ver+"===="+verSession;
|
return "error";
|
}
|
return this.password.equals(Des1.desDecrypt(accesspassword,"")) ? "success" : "fail";
|
}
|
|
@RequestMapping("generate")
|
public void generateNumber(HttpServletRequest request,
|
HttpServletResponse response) {
|
response.setHeader("Pragma", "No-cache");
|
response.setHeader("Cache-Control", "no-cache");
|
response.setDateHeader("Expires", 0);
|
response.setContentType("image/jpeg");
|
// 生成随机字串
|
String verifyCode = VerifyCodeUtils.generateVerifyCode(4);
|
// 存入会话session
|
HttpSession session = request.getSession(true);
|
// 删除以前的验证码
|
session.removeAttribute("verCode");
|
session.setAttribute("verCode", verifyCode.toLowerCase());
|
// 生成图片
|
int w = 80, h = 30;
|
try {
|
VerifyCodeUtils.outputImage(w, h, response.getOutputStream(),
|
verifyCode);
|
} catch (IOException e) {
|
e.printStackTrace();
|
}
|
}
|
}
|