ZeYanG
2018-08-24 d6404ab72e2e0fa8a8c68b7ce14c2f2a6352bfae
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
//
// 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();
        }
    }
}