|
|
|
@ -1,281 +0,0 @@
|
|
|
|
|
package com.dsideal.Sso.Controller;
|
|
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
|
|
|
|
import com.dsideal.Sso.Util.*;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import com.dsideal.Sso.Model.Login;
|
|
|
|
|
import com.jfinal.core.Controller;
|
|
|
|
|
import com.jfinal.kit.PropKit;
|
|
|
|
|
|
|
|
|
|
public class ThirdLoginController extends Controller {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* QQ登录
|
|
|
|
|
*/
|
|
|
|
|
public void qqLogin() {
|
|
|
|
|
HttpServletResponse response = getResponse();
|
|
|
|
|
|
|
|
|
|
JSONObject resultJson = new JSONObject();
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
String qqCode = getPara("code");
|
|
|
|
|
String QqOpenId = ThirdUtil.getQqOpenId(qqCode);
|
|
|
|
|
Map loginMap = Login.dao.getLoginInfoByQqOpenId(QqOpenId);
|
|
|
|
|
if (loginMap == null) {
|
|
|
|
|
resultJson.put("success", false);
|
|
|
|
|
resultJson.put("openid", QqOpenId);
|
|
|
|
|
resultJson.put("msg", "需要绑定用户!");
|
|
|
|
|
renderJson(resultJson);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String sessionId = UUID.randomUUID().toString();
|
|
|
|
|
loginMap.put("login_type", "1");
|
|
|
|
|
SsoLoginHelper.login(response, sessionId, loginMap);
|
|
|
|
|
|
|
|
|
|
resultJson.put("success", true);
|
|
|
|
|
resultJson.put("sessionId", sessionId);
|
|
|
|
|
resultJson.put("personId", loginMap.get("person_id").toString());
|
|
|
|
|
resultJson.put("personName", loginMap.get("person_name").toString());
|
|
|
|
|
|
|
|
|
|
//记录人员登录日志
|
|
|
|
|
LoginLogUtil.WriteLoginLog(loginMap.get("identity_id").toString(), loginMap.get("person_id").toString(), 3, LoginLogUtil.getIpAddr(getRequest()));
|
|
|
|
|
|
|
|
|
|
renderJson(resultJson);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
resultJson.put("success", false);
|
|
|
|
|
resultJson.put("msg", "登录异常,请重试!");
|
|
|
|
|
renderJson(resultJson);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 微信登录
|
|
|
|
|
*/
|
|
|
|
|
public void wxLogin() {
|
|
|
|
|
HttpServletResponse response = getResponse();
|
|
|
|
|
JSONObject resultJson = new JSONObject();
|
|
|
|
|
try {
|
|
|
|
|
String wxCode = getPara("code");
|
|
|
|
|
String wxOpenId = ThirdUtil.getWxOpenId(wxCode);
|
|
|
|
|
Map loginMap = Login.dao.getLoginInfoByWxOpenId(wxOpenId);
|
|
|
|
|
if (loginMap == null) {
|
|
|
|
|
resultJson.put("success", false);
|
|
|
|
|
resultJson.put("openid", wxOpenId);
|
|
|
|
|
resultJson.put("msg", "需要绑定用户!");
|
|
|
|
|
renderJson(resultJson);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
String sessionId = UUID.randomUUID().toString();
|
|
|
|
|
loginMap.put("login_type", "1");
|
|
|
|
|
SsoLoginHelper.login(response, sessionId, loginMap);
|
|
|
|
|
|
|
|
|
|
resultJson.put("success", true);
|
|
|
|
|
resultJson.put("sessionId", sessionId);
|
|
|
|
|
resultJson.put("personId", loginMap.get("person_id").toString());
|
|
|
|
|
resultJson.put("personName", loginMap.get("person_name").toString());
|
|
|
|
|
renderJson(resultJson);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
resultJson.put("success", false);
|
|
|
|
|
resultJson.put("msg", "登录异常,请重试!");
|
|
|
|
|
renderJson(resultJson);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 绑定用户
|
|
|
|
|
*/
|
|
|
|
|
public void bindUser() {
|
|
|
|
|
JSONObject resultJson = new JSONObject();
|
|
|
|
|
|
|
|
|
|
String openId = getPara("openId");
|
|
|
|
|
try {
|
|
|
|
|
openId = AesUtil.aesDecrypt(openId);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
resultJson.put("success", false);
|
|
|
|
|
resultJson.put("msg", "绑定用户异常!");
|
|
|
|
|
renderJson(resultJson);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String personId = getPara("personId");
|
|
|
|
|
try {
|
|
|
|
|
personId = AesUtil.aesDecrypt(personId);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
resultJson.put("success", false);
|
|
|
|
|
resultJson.put("msg", "绑定用户异常!");
|
|
|
|
|
renderJson(resultJson);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 1:QQ 2:微信
|
|
|
|
|
String typeId = getPara("typeId");
|
|
|
|
|
try {
|
|
|
|
|
typeId = AesUtil.aesDecrypt(typeId);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
resultJson.put("success", false);
|
|
|
|
|
resultJson.put("msg", "绑定用户异常!");
|
|
|
|
|
renderJson(resultJson);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
Login.dao.bindUser(openId, personId, typeId);
|
|
|
|
|
|
|
|
|
|
HttpServletResponse response = getResponse();
|
|
|
|
|
Map loginMap = new HashMap();
|
|
|
|
|
// 1:QQ 2:微信
|
|
|
|
|
if (typeId.equals("1")) {
|
|
|
|
|
loginMap = Login.dao.getLoginInfoByQqOpenId(openId);
|
|
|
|
|
} else {
|
|
|
|
|
loginMap = Login.dao.getLoginInfoByWxOpenId(openId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (loginMap == null) {
|
|
|
|
|
resultJson.put("success", false);
|
|
|
|
|
resultJson.put("msg", "绑定用户异常!");
|
|
|
|
|
renderJson(resultJson);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String sessionId = UUID.randomUUID().toString();
|
|
|
|
|
loginMap.put("login_type", "1");
|
|
|
|
|
SsoLoginHelper.login(response, sessionId, loginMap);
|
|
|
|
|
|
|
|
|
|
resultJson.put("success", true);
|
|
|
|
|
resultJson.put("sessionId", sessionId);
|
|
|
|
|
resultJson.put("personId", loginMap.get("person_id").toString());
|
|
|
|
|
resultJson.put("personName", loginMap.get("person_name").toString());
|
|
|
|
|
renderJson(resultJson);
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
resultJson.put("success", false);
|
|
|
|
|
resultJson.put("msg", "绑定用户异常!");
|
|
|
|
|
renderJson(resultJson);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据用户名密码获取用户信息
|
|
|
|
|
*/
|
|
|
|
|
public void getUserInfoByUserNamePwd() {
|
|
|
|
|
HttpServletResponse response = getResponse();
|
|
|
|
|
|
|
|
|
|
JSONObject resultJson = new JSONObject();
|
|
|
|
|
|
|
|
|
|
String userName = getPara("userName");
|
|
|
|
|
String passWord = getPara("passWord");
|
|
|
|
|
String typeId = getPara("typeId");
|
|
|
|
|
try {
|
|
|
|
|
typeId = AesUtil.aesDecrypt(typeId);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
resultJson.put("success", false);
|
|
|
|
|
resultJson.put("msg", "数据异常!");
|
|
|
|
|
renderJson(resultJson);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
if (StringUtils.isBlank(userName)) {
|
|
|
|
|
resultJson.put("success", false);
|
|
|
|
|
resultJson.put("msg", "用户名不允许为空!");
|
|
|
|
|
renderJson(resultJson);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.isBlank(passWord)) {
|
|
|
|
|
resultJson.put("success", false);
|
|
|
|
|
resultJson.put("msg", "密码不允许为空!");
|
|
|
|
|
renderJson(resultJson);
|
|
|
|
|
return;
|
|
|
|
|
} else {
|
|
|
|
|
try {
|
|
|
|
|
passWord = AesUtil.aesDecrypt(passWord);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
resultJson.put("success", false);
|
|
|
|
|
resultJson.put("msg", "数据异常!");
|
|
|
|
|
renderJson(resultJson);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 密码进行ldap算法的md5加密
|
|
|
|
|
LdapPassWordEncoder passEncode = new LdapPassWordEncoder();
|
|
|
|
|
String passwordEncode = passEncode.getLdapPassword(passWord);
|
|
|
|
|
Map loginMap = Login.dao.getLoginInfoByUserName(userName);
|
|
|
|
|
if (loginMap == null || !passwordEncode.equals(loginMap.get("password").toString())) {
|
|
|
|
|
resultJson.put("success", false);
|
|
|
|
|
resultJson.put("msg", "用户名或密码错误!");
|
|
|
|
|
renderJson(resultJson);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (loginMap.get("identity_id").toString().equals("1") || loginMap.get("identity_id").toString().equals("2") || loginMap.get("identity_id").toString().equals("3") || loginMap.get("identity_id").toString().equals("4")) {
|
|
|
|
|
resultJson.put("success", false);
|
|
|
|
|
resultJson.put("msg", "管理员不允许绑定!");
|
|
|
|
|
renderJson(resultJson);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (typeId.equals("1")) {
|
|
|
|
|
if (!loginMap.get("qq_openid").toString().equals("-1")) {
|
|
|
|
|
resultJson.put("success", false);
|
|
|
|
|
resultJson.put("msg", "该用户已绑定QQ,请先解除绑定!");
|
|
|
|
|
renderJson(resultJson);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (!loginMap.get("wx_openid").toString().equals("-1")) {
|
|
|
|
|
resultJson.put("success", false);
|
|
|
|
|
resultJson.put("msg", "该用户已绑定微信,请先解除绑定!");
|
|
|
|
|
renderJson(resultJson);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String sessionId = UUID.randomUUID().toString();
|
|
|
|
|
|
|
|
|
|
SsoLoginHelper.login(response, sessionId, loginMap);
|
|
|
|
|
|
|
|
|
|
resultJson.put("success", true);
|
|
|
|
|
resultJson.put("sessionId", sessionId);
|
|
|
|
|
resultJson.put("personId", loginMap.get("person_id").toString());
|
|
|
|
|
resultJson.put("personName", loginMap.get("person_name").toString());
|
|
|
|
|
renderJson(resultJson);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
resultJson.put("success", false);
|
|
|
|
|
resultJson.put("msg", "绑定账户异常!");
|
|
|
|
|
renderJson(resultJson);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 功能:QQ和微信的回调地址
|
|
|
|
|
*/
|
|
|
|
|
public void getQqWxRedirectUrl() {
|
|
|
|
|
JSONObject resultJson = new JSONObject();
|
|
|
|
|
String defaultRedirectUrl = PropKit.get("qq.wx.redirect.url");
|
|
|
|
|
if (defaultRedirectUrl != null) {
|
|
|
|
|
resultJson.put("success", true);
|
|
|
|
|
resultJson.put("defaultRedirectUrl", defaultRedirectUrl);
|
|
|
|
|
} else {
|
|
|
|
|
resultJson.put("success", false);
|
|
|
|
|
}
|
|
|
|
|
renderJson(resultJson);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|