|
|
@@ -1,5 +1,6 @@
|
|
|
package common.crm;
|
|
|
|
|
|
+import beans.parameter.Parameter;
|
|
|
import com.alibaba.fastjson2.JSONArray;
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
import common.AccessToken;
|
|
|
@@ -19,8 +20,10 @@ import org.springframework.web.bind.annotation.RequestBody;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
import restcontroller.ClientUserInfo;
|
|
|
+import utility.tools.HttpRequest;
|
|
|
import utility.tools.WebRequest;
|
|
|
|
|
|
+import java.net.http.HttpResponse;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.UUID;
|
|
|
@@ -162,6 +165,146 @@ public class sso extends Basic {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @RequestMapping("/yxb/logincheck")
|
|
|
+ @PostMapping
|
|
|
+ @ResponseBody
|
|
|
+ public JSONObject ssologincheck(HttpServletRequest request, HttpServletResponse response, @RequestBody String RequestContent) throws YosException {
|
|
|
+ JSONObject requestcontent = null;
|
|
|
+ try {
|
|
|
+ requestcontent = JSONObject.parseObject(JSONObject.parseObject(RequestContent).toJSONString());
|
|
|
+ } catch (Exception e) {
|
|
|
+ return new ReturnObject_Err().setErrMsg("请求正文格式错误,必须为JSONObject格式,请求内容:" + RequestContent);
|
|
|
+ }
|
|
|
+ String[] mustkeys = {"accesstoken", "accountno"};
|
|
|
+ for (String mustkey : mustkeys) {
|
|
|
+ if (!requestcontent.containsKey(mustkey)) {
|
|
|
+ return new ReturnObject_Err().setErrMsg("json缺少KEY" + mustkey);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String accesstoken = requestcontent.getString("accesstoken");
|
|
|
+ String accountno = requestcontent.getString("accountno");
|
|
|
+
|
|
|
+ JSONObject object = new JSONObject();
|
|
|
+ object.put("code", 0);
|
|
|
+ object.put("status", 0);
|
|
|
+ object.put("msg", "无效的token");
|
|
|
+ if (AccessToken.exists(accesstoken)) {
|
|
|
+ Row row = AccessToken.get(accesstoken).getUserRow();
|
|
|
+ if (accountno.equals(row.getString("accountno"))) {
|
|
|
+ object.put("code", 1);
|
|
|
+ object.put("status", 1);
|
|
|
+ object.put("msg", "token有效");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return object;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @RequestMapping("/yxb")
|
|
|
+ @PostMapping
|
|
|
+ @ResponseBody
|
|
|
+ public JSONObject loginFromYXB(HttpServletRequest request, HttpServletResponse response, @RequestBody String RequestContent) throws YosException {
|
|
|
+ HttpSession session = request.getSession(true);
|
|
|
+ String sessionID = session.getId();
|
|
|
+ DBConnect connect = new DBConnect();
|
|
|
+ /**
|
|
|
+ * 验证请求正文是否为规范的SONObject格式
|
|
|
+ */
|
|
|
+ JSONObject requestcontent = null;
|
|
|
+ try {
|
|
|
+ requestcontent = JSONObject.parseObject(JSONObject.parseObject(RequestContent).toJSONString());
|
|
|
+ } catch (Exception e) {
|
|
|
+ this.createLoginLog(RequestContent, request, false, new JSONArray(), "请求格式不正确!");
|
|
|
+ return new ReturnObject_Err().setErrMsg("请求正文格式错误,必须为JSONObject格式");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 验证请求正文中是否包含必填的键值
|
|
|
+ */
|
|
|
+ String[] mustkeys = {"accountno", "password", "systemclient"};
|
|
|
+ for (String mustkey : mustkeys) {
|
|
|
+ if (!requestcontent.containsKey(mustkey)) {
|
|
|
+ this.createLoginLog(RequestContent, request, false, new JSONArray(), "json缺少KEY" + mustkey);
|
|
|
+ return new ReturnObject_Err().setErrMsg("json缺少KEY" + mustkey);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String accountno = requestcontent.getString("accountno");
|
|
|
+ String inputpassword = requestcontent.getString("password");//即营销宝的accesstoken
|
|
|
+
|
|
|
+ String systemclient = requestcontent.getString("systemclient");//登陆操作端
|
|
|
+ if (connect.runSqlQuery("select systemclient from sys_systemclient where systemclient='" + systemclient + "'").isEmpty()) {
|
|
|
+ this.createLoginLog(RequestContent, request, false, new JSONArray(), "不存在的操作端");
|
|
|
+ return new ReturnObject_Err().setErrMsg("不存在的操作端" + systemclient);
|
|
|
+ }
|
|
|
+
|
|
|
+ boolean passwordVerificationPassed = false;//密码校验是否通过,默认不通过
|
|
|
+ JSONObject yxbtokencheck = new JSONObject();
|
|
|
+ yxbtokencheck.put("accesstoken", inputpassword);
|
|
|
+ yxbtokencheck.put("accountno", accountno);
|
|
|
+
|
|
|
+ HttpResponse<String> post = new HttpRequest().POST(yxbtokencheck.toString(), Parameter.getString("yxb_sso_login_url") + "/logincheck");
|
|
|
+ String body = post.body();
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(body);
|
|
|
+ if (jsonObject.getIntValue("code") == 1) {//token验证有效
|
|
|
+ Rows users = connect.runSqlQuery("select userid,status,failedlogins from sys_users where accountno='" + accountno + "'");
|
|
|
+ if (users.isNotEmpty()) {
|
|
|
+ Row user = users.get(0);
|
|
|
+ String status = user.getString("status");
|
|
|
+ if (status.equalsIgnoreCase("ACTIVE")) {
|
|
|
+ passwordVerificationPassed = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (passwordVerificationPassed) {
|
|
|
+ QuerySQL userQuery = SQLFactory.createQuerySQL(connect, "sys_users", "userid", "name", "createdate", "phonenumber", "status", "accountno", "passwordchangedate", "isthirddeveloper").setTableAlias("t1");
|
|
|
+ userQuery.addJoinTable(BaseClass.JOINTYPE.inner, "sys_usersite", "t2", "t1.userid=t2.userid", "usersiteid", "siteid", "usertype");
|
|
|
+ userQuery.addJoinTable(BaseClass.JOINTYPE.inner, "sys_site", "t3", "t2.siteid=t3.siteid", "sitename");
|
|
|
+ userQuery.addJoinTable(BaseClass.JOINTYPE.left, "sys_hr", "t4", "t1.userid=t4.userid and t2.siteid=t4.siteid", "departmentid", "hrid");
|
|
|
+ userQuery.addJoinTable(BaseClass.JOINTYPE.inner, "sys_site_parameter", "t5", "t2.siteid=t5.siteid and t5.loginmode_account=1");
|
|
|
+ userQuery.setWhere("t1.status", "ACTIVE");
|
|
|
+ userQuery.setWhere("t1.accountno", accountno);
|
|
|
+
|
|
|
+ Rows userrows = userQuery.query();
|
|
|
+ if (userrows.isEmpty()) {
|
|
|
+ JSONObject object = new JSONObject();
|
|
|
+ object.put("code", 0);
|
|
|
+ object.put("status", 0);
|
|
|
+ object.put("msg", "没有为当前账号配分配有效的角色");
|
|
|
+ this.createLoginLog(RequestContent, request, false, new JSONArray(), "没有为当前账号配分配有效的角色");
|
|
|
+ return object;
|
|
|
+ }
|
|
|
+
|
|
|
+ long userid = 0;
|
|
|
+ for (Row userrow : userrows) {
|
|
|
+ userid = userrow.getLong("userid");//用户id
|
|
|
+ long usersiteid = userrow.getLong("usersiteid");//用户角色id
|
|
|
+
|
|
|
+ userrow.put("logintime", BaseClass.getDateTime_Str());
|
|
|
+ userrow.put("systemclient", systemclient);
|
|
|
+ userrow.put("ip", WebRequest.getRequestIP(request));
|
|
|
+ userrow.put("useragent", WebRequest.getUserAgent(request));
|
|
|
+ userrow.putAll(ClientUserInfo.setLoginReturn(usersiteid, userrow));
|
|
|
+ userrow.put("token", AccessToken.create(systemclient, sessionID, userrow).getToken());
|
|
|
+ }
|
|
|
+ JSONObject object = new JSONObject();
|
|
|
+ object.put("code", 1);
|
|
|
+ object.put("status", 1);
|
|
|
+ object.put("msg", "成功");
|
|
|
+ object.put("account_list", userrows.toJsonArray());
|
|
|
+ String remind = remindChangePassword(userid, inputpassword, userrows.toArray("siteid"));
|
|
|
+ object.put("remindchangepassword", remind.isEmpty() ? 0 : 1);
|
|
|
+ object.put("remindchangepassword_str", remind);
|
|
|
+ this.createLoginLog(RequestContent, request, true, userrows.toJsonArray("userid"), "null");
|
|
|
+ return object;
|
|
|
+ } else {
|
|
|
+ JSONObject object = new JSONObject();
|
|
|
+ object.put("code", 0);
|
|
|
+ object.put("status", 0);
|
|
|
+ object.put("msg", "登录验证已失效,请重新登录CRM!");
|
|
|
+ this.createLoginLog(RequestContent, request, false, new JSONArray(), "登录验证已失效,请重新登录CRM!");
|
|
|
+ return object;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
private boolean createAgentUser(DBConnect dbConnect, long sys_enterpriseid, String accountno, String name, String phonenumber) {
|
|
|
try {
|