|
扩展了系统的登录login.J文件,改:将下面的
改为了无密码的登录方法,其他的都不变;但是启动服务器,清除浏览器缓存后,第一次登录成功跳转到首页出来了,然后都会出现登录系统后才能执行 biz action 请求;
第二次以后又都是好的了,不会再出现了,但是启动服务器,清除浏览器缓存后有出现,这个怎么解决呢??
具体代码如下:
public void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// hcr 支持oauth登录
AuthUtils.loginAuthServer(response);
String bsessionid = null;
String sysCode = null;
String orgVersion = null;
Cookie[] cookies = request.getCookies();
if (cookies != null) {
for (int i = 0; i < cookies.length; i++) {
String name = cookies.getName();
if (name.equals("bsessionid")) {
bsessionid = cookies.getValue();
}
}
}
if (bsessionid == null) {
// ActionResult result = LoginAction.execute(request);----系统有密码登录
// ==gf--无密码登录---2019年7月16日11:47:15==start=============
String fPhone = request.getParameter("fPhone");
String username = request.getParameter("username");
String password = request.getParameter("password");
int cuser = checkUser(fPhone, password);// 再次检查会员名称和密码是否对应
if (cuser == 0) {
throw new RuntimeException("手机号或密码错误,请重试");
}
String ip = request.getRemoteAddr();
String language = "zh_CN";
Date loginDate = new Date(System.currentTimeMillis());
// 调用ntLoginAction不用密码登录
Action action = new Action();
action.setProcess("/SA/OPM/system/systemProcess");
action.setActivity("mainActivity");
action.setName("ntLoginAction");
action.setParameter("name", username);
action.setParameter("loginDate", new java.sql.Date(System.currentTimeMillis()));
action.setParameter("ip", "127.0.0.1");
action.setParameter("options", new HashMap<String, Object>());
action.setParameter("lang", language);
ActionResult result = ActionEngine.invokeActions(JustepConfig.getBusinessServer() + "/login2", null, action.asXML().getBytes("UTF-8"), null, ActionUtils.JSON_CONTENT_TYPE,
ActionUtils.XML_CONTENT_TYPE, null, language, "post", null);
// ==gf--无密码登录---2019年7月16日11:47:15==end=============
if (result.isSuccess()) {
bsessionid = result.getBSessionID();
sysCode = result.getSysCode();
// get orgVersion
List<Object> datas = result.getDatas();
JSONObject resultParam = (JSONObject) datas.get(0);
@SuppressWarnings("rawtypes")
List values = (List) resultParam.get("value");
orgVersion = (String) values.get(values.size() - 1);
} else {
JSONObject content = null;
String code = result.getCode();
if (ClientMessages.CON_ERROR1.equals(code) || ClientMessages.ACTION_ERROR1.equals(code)) {
content = new JSONObject();
content.put("flag", false);
content.put("message", result.getMessage());
} else {
content = (JSONObject) result.getContent();
}
response.setCharacterEncoding("UTF-8");
response.setContentType(ActionUtils.JSON_CONTENT_TYPE);
OutputStream output = response.getOutputStream();
output.write(content.toString().getBytes("UTF-8"));
output.flush();
output.close();
return;
}
}
// 伪装参数, 获取上下文信息
String useName = request.getParameter("username");
String executor = request.getParameter("executor");
JSONObject data;
JSONObject context;
if (useName == null || !useCache || !SystemCache.cache.containsKey(useName)) {
Map<String, String> params = new HashMap<String, String>();
params.put("process", "/SA/OPM/system/systemProcess");
params.put("activity", "mainActivity");
params.put("$functionTree", "true");
params.put("$widgetList", "true");
if (executor != null)
params.put("executor", executor);
else
params.put("$agentList", "true");
params.put("bsessionid", bsessionid);
context = (JSONObject) UIUtils.getWindowContext(new ClassicPortalRequestWrapper(request, params), null, false);
if (context.getBoolean("flag")) {
data = (JSONObject) context.get("data");
} else {
response.setCharacterEncoding("UTF-8");
response.setContentType(ActionUtils.JSON_CONTENT_TYPE);
OutputStream output = response.getOutputStream();
output.write(context.toString().getBytes("UTF-8"));
output.flush();
output.close();
return;
}
// 取系统注入代码
context.put("sys", sysCode);
context.put("bsessionid", bsessionid);
// 不能缓存
data.put("bsessionid", bsessionid);
JSONObject pid = (JSONObject) data.get("bizParams");
pid = (JSONObject) pid.get("value");
String personID = (String) pid.get("currentPersonID");
data.put("layout", this.getLayout(personID, bsessionid));
data.put("orgVersion", orgVersion);
response.setCharacterEncoding("UTF-8");
response.setContentType(ActionUtils.JSON_CONTENT_TYPE);
PrintWriter out = response.getWriter();
out.write(context.toString());
out.flush();
if (useCache && (useName != null)) {
context.put("sys", "__sysCode__");
context.put("bsessionid", "__bsessionid__");
data.put("bsessionid", "__bsessionid__");
data.put("orgVersion", "__orgVersion__");
String ctx = context.toJSONString();
SystemCache.cache.put(useName, ctx);
}
} else {
String ctx = SystemCache.cache.get(useName);
ctx = ctx.replace("__bsessionid__", bsessionid);
if (sysCode != null) {
ctx = ctx.replace("__sysCode__", sysCode);
} else {
ctx = ctx.replace("__sysCode__", "");
}
if (orgVersion != null) {
ctx = ctx.replace("__orgVersion__", orgVersion);
} else {
ctx = ctx.replace("__orgVersion__", "");
}
response.setCharacterEncoding("UTF-8");
response.setContentType(ActionUtils.JSON_CONTENT_TYPE);
PrintWriter out = response.getWriter();
out.write(ctx);
out.flush();
}
}
|
|