|
|
@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
package com.dsideal.sso.Controller;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.dsideal.sso.Interceptor.EmptyInterface;
|
|
|
|
|
|
|
|
import com.dsideal.sso.Util.CommonUtil;
|
|
|
|
|
|
|
|
import com.dsideal.sso.Util.SsoLoginHelper;
|
|
|
|
|
|
|
|
import com.jfinal.aop.Before;
|
|
|
|
|
|
|
|
import com.jfinal.ext.interceptor.POST;
|
|
|
|
|
|
|
|
import com.jfinal.kit.StrKit;
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
|
|
|
import com.jfinal.core.Controller;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class AppLoginController extends Controller {
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* app登录
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param username 用户名
|
|
|
|
|
|
|
|
* @param password 密码
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
@Before({POST.class})
|
|
|
|
|
|
|
|
@EmptyInterface({"username", "password"})
|
|
|
|
|
|
|
|
public void doLogin(String username, String password) {
|
|
|
|
|
|
|
|
JSONObject resultJson = new JSONObject();
|
|
|
|
|
|
|
|
String passwordEncode = CommonUtil.getLdapPassword(password);
|
|
|
|
|
|
|
|
Map<String, String> loginMap = CommonUtil.getLoginRouteMap(username);
|
|
|
|
|
|
|
|
if (passwordEncode != null && (loginMap == null || !passwordEncode.equals(loginMap.get("password")))) {
|
|
|
|
|
|
|
|
resultJson.put("success", false);
|
|
|
|
|
|
|
|
resultJson.put("msg", "用户名或密码错误!");
|
|
|
|
|
|
|
|
renderJson(resultJson);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String sessionId = UUID.randomUUID().toString();
|
|
|
|
|
|
|
|
SsoLoginHelper.login(sessionId, loginMap);
|
|
|
|
|
|
|
|
resultJson.put("success", true);
|
|
|
|
|
|
|
|
resultJson.put("sessionId", sessionId);
|
|
|
|
|
|
|
|
if (loginMap != null) {
|
|
|
|
|
|
|
|
resultJson.put("personId", loginMap.get("person_id"));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (loginMap != null) {
|
|
|
|
|
|
|
|
resultJson.put("personName", loginMap.get("person_name"));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (loginMap != null) {
|
|
|
|
|
|
|
|
resultJson.put("bureauId", loginMap.get("bureau_id"));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (loginMap != null) {
|
|
|
|
|
|
|
|
resultJson.put("identityId", loginMap.get("identity_id"));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
renderJson(resultJson);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 功能:登录检查
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public void loginCheck() {
|
|
|
|
|
|
|
|
JSONObject resultJson = new JSONObject();
|
|
|
|
|
|
|
|
boolean flag = true;
|
|
|
|
|
|
|
|
if (flag) {
|
|
|
|
|
|
|
|
String sessionId = getPara("sessionId");
|
|
|
|
|
|
|
|
if (!sessionId.equals("null") && sessionId != null && sessionId.length() != 0) {
|
|
|
|
|
|
|
|
Map loginMap = SsoLoginHelper.loginCheck(sessionId);
|
|
|
|
|
|
|
|
if (loginMap == null) {
|
|
|
|
|
|
|
|
resultJson.put("success", false);
|
|
|
|
|
|
|
|
resultJson.put("msg", "sessionId 已失效!");
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
resultJson.put("success", true);
|
|
|
|
|
|
|
|
resultJson.put("sessionId", sessionId);
|
|
|
|
|
|
|
|
resultJson.put("personId", loginMap.get("person_id").toString());
|
|
|
|
|
|
|
|
resultJson.put("personName", loginMap.get("person_name").toString());
|
|
|
|
|
|
|
|
resultJson.put("bureauId", loginMap.get("bureau_id").toString());
|
|
|
|
|
|
|
|
resultJson.put("identityId", loginMap.get("identity_id").toString());
|
|
|
|
|
|
|
|
resultJson.put("city_id", loginMap.get("city_id").toString());
|
|
|
|
|
|
|
|
resultJson.put("area_id", loginMap.get("area_id").toString());
|
|
|
|
|
|
|
|
//loginType 1:正常登录 2:切换登录 如果为切换登录main_person_id不能写-1
|
|
|
|
|
|
|
|
String loginType = loginMap.get("login_type").toString();
|
|
|
|
|
|
|
|
if (loginType.equals("1")) {
|
|
|
|
|
|
|
|
resultJson.put("mainPersonId", loginMap.get("main_person_id").toString());
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
resultJson.put("mainPersonId", Login.dao.getMainAccountPersonIdByPersonId(loginMap.get("person_id").toString()));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
resultJson.put("success", false);
|
|
|
|
|
|
|
|
resultJson.put("msg", "sessionId 已失效!");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
renderJson(resultJson);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* app登出
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @throws Exception
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public void logout() {
|
|
|
|
|
|
|
|
String sessionId = getPara("sessionId");
|
|
|
|
|
|
|
|
SsoLoginHelper.logout(sessionId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|