|
|
|
@ -5,6 +5,7 @@ import cn.jlw.Interceptor.SCoreUser;
|
|
|
|
|
import cn.jlw.Interceptor.TStudent;
|
|
|
|
|
import cn.jlw.Interceptor.TTeacher;
|
|
|
|
|
import cn.jlw.token.TokenService;
|
|
|
|
|
import cn.jlw.util.EnumUtil;
|
|
|
|
|
import cn.jlw.util.ToolUtils;
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import com.auth0.jwt.JWT;
|
|
|
|
@ -15,6 +16,7 @@ import com.auth0.jwt.interfaces.Claim;
|
|
|
|
|
import com.auth0.jwt.interfaces.DecodedJWT;
|
|
|
|
|
import com.ibeetl.admin.core.entity.CoreOrg;
|
|
|
|
|
import com.ibeetl.admin.core.entity.CoreUser;
|
|
|
|
|
import com.ibeetl.admin.core.enums.MenuEnums;
|
|
|
|
|
import com.ibeetl.admin.core.file.FileService;
|
|
|
|
|
import com.ibeetl.admin.core.rbac.UserLoginInfo;
|
|
|
|
|
import com.ibeetl.admin.core.rbac.tree.MenuItem;
|
|
|
|
@ -49,7 +51,7 @@ import java.util.*;
|
|
|
|
|
import static cn.jlw.Interceptor.AuthenticationInterceptor.getToken;
|
|
|
|
|
import static cn.jlw.Interceptor.AuthenticationInterceptor.indexTokenMap;
|
|
|
|
|
import static cn.jlw.token.TokenService.updateByIds;
|
|
|
|
|
import static com.ibeetl.admin.core.enums.MenuEnums.*;
|
|
|
|
|
import static com.ibeetl.admin.core.enums.MenuEnums.JT_S_02;
|
|
|
|
|
import static com.ibeetl.admin.core.service.CorePlatformService.tokenSessionMap;
|
|
|
|
|
|
|
|
|
|
@Controller
|
|
|
|
@ -678,6 +680,124 @@ public class IndexController {
|
|
|
|
|
return view;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// @PostMapping("/login.json")
|
|
|
|
|
// @ResponseBody
|
|
|
|
|
// public JsonResult login(HttpServletRequest request, HttpServletResponse response,String code, String password, Integer type, Long typeId) {
|
|
|
|
|
// UniversitiesCollegesJurisdictionExperimentalSystem uSystem = new UniversitiesCollegesJurisdictionExperimentalSystem();
|
|
|
|
|
// uSystem.setType(type);
|
|
|
|
|
// uSystem.setTypeId(typeId);
|
|
|
|
|
// Cookie c1 = new Cookie("JSESSIONID", request.getSession().getId());
|
|
|
|
|
// c1.setPath("/");
|
|
|
|
|
// response.addCookie(c1);
|
|
|
|
|
// UserLoginInfo info = null;
|
|
|
|
|
// try {
|
|
|
|
|
// info = userService.login(code, password);
|
|
|
|
|
// }catch (Exception e){
|
|
|
|
|
// return JsonResult.failMessage(e.getMessage());
|
|
|
|
|
// }
|
|
|
|
|
// CoreUser user = info.getUser();
|
|
|
|
|
// CoreOrg currentOrg = info.getOrgs().get(0);
|
|
|
|
|
// for (CoreOrg org : info.getOrgs()) {
|
|
|
|
|
// if (org.getId().equals(user.getOrgId())) {
|
|
|
|
|
// currentOrg = org;
|
|
|
|
|
// break;
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// info.setCurrentOrg(currentOrg);
|
|
|
|
|
//
|
|
|
|
|
// if(null != user && !Arrays.asList(JT_S_01.name(), JT_S_04.name()).contains(user.getJobType1())){//非管理员(包含学校管理员、超管)
|
|
|
|
|
//// if(null != type && null != typeId){
|
|
|
|
|
// UniversitiesColleges universitiesColleges = universitiesCollegesService.getByOrgId(user.getOrgId());
|
|
|
|
|
// if(null != universitiesColleges && ((Integer)1).equals(universitiesColleges.getUniversitiesCollegesStatus())){
|
|
|
|
|
// uSystem.setUniversitiesCollegesId(universitiesColleges.getUniversitiesCollegesId());
|
|
|
|
|
// uSystem.set("useTypes","1,2");
|
|
|
|
|
// List<UniversitiesCollegesJurisdictionExperimentalSystem>uSystemList = universitiesCollegesJurisdictionExperimentalSystemService.getValues(uSystem);
|
|
|
|
|
// if(null != uSystemList && uSystemList.size()>0){
|
|
|
|
|
// uSystem = uSystemList.get(0);
|
|
|
|
|
// }
|
|
|
|
|
// if(null != uSystem && null != uSystem.getUniversitiesCollegesJurisdictionExperimentalSystemId()){
|
|
|
|
|
// if(uSystem.getUseStartTime().getTime() <= System.currentTimeMillis() && uSystem.getUseEndTime().getTime() > System.currentTimeMillis()){
|
|
|
|
|
// String msg = "";
|
|
|
|
|
// if("JT_S_02".equals(user.getJobType1())){//如果是老师 快到期通知
|
|
|
|
|
// if(uSystem.getUseEndTime().getTime() - System.currentTimeMillis() < 259200000L){ //少于3天做通知
|
|
|
|
|
// msg = "请注意,系统即将过期";
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// JsonResult jsonResult = new JsonResult();
|
|
|
|
|
// jsonResult.setCode(JsonReturnCode.SUCCESS.getCode());
|
|
|
|
|
// jsonResult.setMsg(msg);
|
|
|
|
|
//
|
|
|
|
|
// if(JT_S_02.equals(user.getJobType1())){//老师
|
|
|
|
|
// Teacher teacher = teacherService.getByUserId(user.getId());
|
|
|
|
|
// String token = tokenService.getToken(teacher);
|
|
|
|
|
//
|
|
|
|
|
// if(StringUtils.isNotBlank(token)){
|
|
|
|
|
//
|
|
|
|
|
// String keyId = UUID.randomUUID().toString();
|
|
|
|
|
// indexTokenMap.put(keyId,token);
|
|
|
|
|
// jsonResult.setData(keyId);
|
|
|
|
|
//
|
|
|
|
|
// //断token的尾巴
|
|
|
|
|
// if(StringUtils.isNotBlank(token)){
|
|
|
|
|
// if(token.split("\\.").length > 3){
|
|
|
|
|
// String loginTime = token.split("\\.")[3];
|
|
|
|
|
// token = token.replace("."+loginTime,"");
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// // 登录信息存放Session
|
|
|
|
|
// webPlatformService.setUserInfoToSessionByIdentity(info.getUser());
|
|
|
|
|
// platformService.setLoginUser(info.getUser(), info.getCurrentOrg(), info.getOrgs(), uSystem);
|
|
|
|
|
// tokenSessionMap.put(token,new Object[]{user, info.getCurrentOrg(), info.getOrgs(), uSystem});
|
|
|
|
|
// return jsonResult;
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// }else if(JT_S_03.equals(user.getJobType1())){//学生
|
|
|
|
|
//
|
|
|
|
|
// Student s = studentService.getByUserId(user.getId());
|
|
|
|
|
// String token = tokenService.getToken(s);
|
|
|
|
|
//
|
|
|
|
|
// if(StringUtils.isNotBlank(token)){
|
|
|
|
|
//
|
|
|
|
|
// String keyId = UUID.randomUUID().toString();
|
|
|
|
|
// indexTokenMap.put(keyId,token);
|
|
|
|
|
// jsonResult.setData(keyId);
|
|
|
|
|
//
|
|
|
|
|
// //断token的尾巴
|
|
|
|
|
// if(StringUtils.isNotBlank(token)){
|
|
|
|
|
// if(token.split("\\.").length > 3){
|
|
|
|
|
// String loginTime = token.split("\\.")[3];
|
|
|
|
|
// token = token.replace("."+loginTime,"");
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// tokenSessionMap.put(token,new Object[]{user, info.getCurrentOrg(), info.getOrgs(), uSystem});
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// // 登录信息存放Session
|
|
|
|
|
// webPlatformService.setUserInfoToSessionByIdentity(info.getUser());
|
|
|
|
|
// platformService.setLoginUser(info.getUser(), info.getCurrentOrg(), info.getOrgs(), uSystem);
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// return jsonResult;
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }else {
|
|
|
|
|
// return JsonResult.failMessage("登录失败,此院校不存在");
|
|
|
|
|
// }
|
|
|
|
|
//// }
|
|
|
|
|
//// return JsonResult.failMessage("登录失败,没有此系统权限");
|
|
|
|
|
// }else {
|
|
|
|
|
// // 记录登录信息到session
|
|
|
|
|
// this.platformService.setLoginUser(info.getUser(), info.getCurrentOrg(), info.getOrgs(), uSystem);
|
|
|
|
|
// // 登录信息存放Session。这里可能是学校管理员
|
|
|
|
|
// webPlatformService.setUserInfoToSessionByIdentity(info.getUser());
|
|
|
|
|
// }
|
|
|
|
|
// return JsonResult.success();
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@PostMapping("/login.json")
|
|
|
|
|
@ResponseBody
|
|
|
|
|
public JsonResult login(HttpServletRequest request, HttpServletResponse response,String code, String password, Integer type, Long typeId) {
|
|
|
|
@ -703,120 +823,100 @@ public class IndexController {
|
|
|
|
|
}
|
|
|
|
|
info.setCurrentOrg(currentOrg);
|
|
|
|
|
|
|
|
|
|
if(null != user && !Arrays.asList(JT_S_01.name(), JT_S_04.name()).contains(user.getJobType1())){//非管理员(包含学校管理员、超管)
|
|
|
|
|
// if(null != type && null != typeId){
|
|
|
|
|
UniversitiesColleges universitiesColleges = universitiesCollegesService.getByOrgId(user.getOrgId());
|
|
|
|
|
if(null != universitiesColleges && ((Integer)1).equals(universitiesColleges.getUniversitiesCollegesStatus())){
|
|
|
|
|
uSystem.setUniversitiesCollegesId(universitiesColleges.getUniversitiesCollegesId());
|
|
|
|
|
uSystem.set("useTypes","1,2");
|
|
|
|
|
List<UniversitiesCollegesJurisdictionExperimentalSystem>uSystemList = universitiesCollegesJurisdictionExperimentalSystemService.getValues(uSystem);
|
|
|
|
|
if(null != uSystemList && uSystemList.size()>0){
|
|
|
|
|
uSystem = uSystemList.get(0);
|
|
|
|
|
}
|
|
|
|
|
if(null != uSystem && null != uSystem.getUniversitiesCollegesJurisdictionExperimentalSystemId()){
|
|
|
|
|
if(uSystem.getUseStartTime().getTime() <= System.currentTimeMillis() && uSystem.getUseEndTime().getTime() > System.currentTimeMillis()){
|
|
|
|
|
String msg = "";
|
|
|
|
|
if("JT_S_02".equals(user.getJobType1())){//如果是老师 快到期通知
|
|
|
|
|
if(uSystem.getUseEndTime().getTime() - System.currentTimeMillis() < 259200000L){ //少于3天做通知
|
|
|
|
|
msg = "请注意,系统即将过期";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
JsonResult jsonResult = new JsonResult();
|
|
|
|
|
jsonResult.setCode(JsonReturnCode.SUCCESS.getCode());
|
|
|
|
|
jsonResult.setMsg(msg);
|
|
|
|
|
switch (EnumUtil.fromString(MenuEnums.class, user.getJobType1())) {
|
|
|
|
|
|
|
|
|
|
if(JT_S_02.equals(user.getJobType1())){//老师
|
|
|
|
|
Teacher teacher = teacherService.getByUserId(user.getId());
|
|
|
|
|
String token = tokenService.getToken(teacher);
|
|
|
|
|
// 超管和学校管理员
|
|
|
|
|
case JT_S_01:
|
|
|
|
|
case JT_S_04: {
|
|
|
|
|
// 记录登录信息到session
|
|
|
|
|
this.platformService.setLoginUser(info.getUser(), info.getCurrentOrg(), info.getOrgs(), uSystem);
|
|
|
|
|
// 登录信息存放Session。这里可能是学校管理员
|
|
|
|
|
webPlatformService.setUserInfoToSessionByIdentity(info.getUser());
|
|
|
|
|
} break;
|
|
|
|
|
|
|
|
|
|
if(StringUtils.isNotBlank(token)){
|
|
|
|
|
// 教师
|
|
|
|
|
case JT_S_02: {
|
|
|
|
|
|
|
|
|
|
String keyId = UUID.randomUUID().toString();
|
|
|
|
|
indexTokenMap.put(keyId,token);
|
|
|
|
|
jsonResult.setData(keyId);
|
|
|
|
|
// 验证使用权,是否到期
|
|
|
|
|
UniversitiesColleges universitiesColleges = universitiesCollegesService.getByOrgId(user.getOrgId());
|
|
|
|
|
|
|
|
|
|
//断token的尾巴
|
|
|
|
|
if(StringUtils.isNotBlank(token)){
|
|
|
|
|
if(token.split("\\.").length > 3){
|
|
|
|
|
String loginTime = token.split("\\.")[3];
|
|
|
|
|
token = token.replace("."+loginTime,"");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (universitiesColleges == null) {
|
|
|
|
|
return JsonResult.failMessage("登录失败,此院校不存在");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 登录信息存放Session
|
|
|
|
|
webPlatformService.setUserInfoToSessionByIdentity(info.getUser());
|
|
|
|
|
platformService.setLoginUser(info.getUser(), info.getCurrentOrg(), info.getOrgs(), uSystem);
|
|
|
|
|
tokenSessionMap.put(token,new Object[]{user, info.getCurrentOrg(), info.getOrgs(), uSystem});
|
|
|
|
|
return jsonResult;
|
|
|
|
|
if(null != universitiesColleges && ((Integer)1).equals(universitiesColleges.getUniversitiesCollegesStatus())) {
|
|
|
|
|
uSystem.setUniversitiesCollegesId(universitiesColleges.getUniversitiesCollegesId());
|
|
|
|
|
uSystem.set("useTypes", "1,2");
|
|
|
|
|
List<UniversitiesCollegesJurisdictionExperimentalSystem> uSystemList = universitiesCollegesJurisdictionExperimentalSystemService.getValues(uSystem);
|
|
|
|
|
if (null != uSystemList && uSystemList.size() > 0) {
|
|
|
|
|
uSystem = uSystemList.get(0);
|
|
|
|
|
}
|
|
|
|
|
if (null != uSystem && null != uSystem.getUniversitiesCollegesJurisdictionExperimentalSystemId()) {
|
|
|
|
|
if (uSystem.getUseStartTime().getTime() <= System.currentTimeMillis() && uSystem.getUseEndTime().getTime() > System.currentTimeMillis()) {
|
|
|
|
|
|
|
|
|
|
//如果是老师 快到期通知
|
|
|
|
|
if (JT_S_02.name().equals(user.getJobType1())) {
|
|
|
|
|
//少于3天做通知
|
|
|
|
|
if (uSystem.getUseEndTime().getTime() - System.currentTimeMillis() < 259200000L) {
|
|
|
|
|
return JsonResult.successMessage("请注意,系统即将过期");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}else if(JT_S_03.equals(user.getJobType1())){//学生
|
|
|
|
|
Teacher teacher = teacherService.getByUserId(user.getId());
|
|
|
|
|
String teacherToken = tokenService.getToken(teacher);
|
|
|
|
|
|
|
|
|
|
Student s = studentService.getByUserId(user.getId());
|
|
|
|
|
String token = tokenService.getToken(s);
|
|
|
|
|
if(StringUtils.isNotBlank(teacherToken)) {
|
|
|
|
|
|
|
|
|
|
if(StringUtils.isNotBlank(token)){
|
|
|
|
|
String keyId = UUID.randomUUID().toString();
|
|
|
|
|
indexTokenMap.put(keyId, teacherToken);
|
|
|
|
|
|
|
|
|
|
String keyId = UUID.randomUUID().toString();
|
|
|
|
|
indexTokenMap.put(keyId,token);
|
|
|
|
|
jsonResult.setData(keyId);
|
|
|
|
|
//断token的尾巴
|
|
|
|
|
if (StringUtils.isNotBlank(teacherToken)) {
|
|
|
|
|
if (teacherToken.split("\\.").length > 3) {
|
|
|
|
|
String loginTime = teacherToken.split("\\.")[3];
|
|
|
|
|
teacherToken = teacherToken.replace("." + loginTime, "");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//断token的尾巴
|
|
|
|
|
if(StringUtils.isNotBlank(token)){
|
|
|
|
|
if(token.split("\\.").length > 3){
|
|
|
|
|
String loginTime = token.split("\\.")[3];
|
|
|
|
|
token = token.replace("."+loginTime,"");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 登录信息存放Session
|
|
|
|
|
webPlatformService.setUserInfoToSessionByIdentity(info.getUser());
|
|
|
|
|
platformService.setLoginUser(info.getUser(), info.getCurrentOrg(), info.getOrgs(), uSystem);
|
|
|
|
|
tokenSessionMap.put(teacherToken, new Object[]{user, info.getCurrentOrg(), info.getOrgs(), uSystem});
|
|
|
|
|
return JsonResult.success(keyId);
|
|
|
|
|
}
|
|
|
|
|
} break;
|
|
|
|
|
|
|
|
|
|
tokenSessionMap.put(token,new Object[]{user, info.getCurrentOrg(), info.getOrgs(), uSystem});
|
|
|
|
|
}
|
|
|
|
|
// 学生
|
|
|
|
|
case JT_S_03: {
|
|
|
|
|
Student s = studentService.getByUserId(user.getId());
|
|
|
|
|
String studentToken = tokenService.getToken(s);
|
|
|
|
|
|
|
|
|
|
// 登录信息存放Session
|
|
|
|
|
webPlatformService.setUserInfoToSessionByIdentity(info.getUser());
|
|
|
|
|
platformService.setLoginUser(info.getUser(), info.getCurrentOrg(), info.getOrgs(), uSystem);
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.isNotBlank(studentToken)) {
|
|
|
|
|
|
|
|
|
|
return jsonResult;
|
|
|
|
|
String keyId = UUID.randomUUID().toString();
|
|
|
|
|
indexTokenMap.put(keyId, studentToken);
|
|
|
|
|
|
|
|
|
|
//断token的尾巴
|
|
|
|
|
if (StringUtils.isNotBlank(studentToken)) {
|
|
|
|
|
if (studentToken.split("\\.").length > 3) {
|
|
|
|
|
String loginTime = studentToken.split("\\.")[3];
|
|
|
|
|
studentToken = studentToken.replace("." + loginTime, "");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}else {
|
|
|
|
|
return JsonResult.failMessage("登录失败,此院校不存在");
|
|
|
|
|
}
|
|
|
|
|
// }
|
|
|
|
|
// return JsonResult.failMessage("登录失败,没有此系统权限");
|
|
|
|
|
}else {
|
|
|
|
|
// 记录登录信息到session
|
|
|
|
|
this.platformService.setLoginUser(info.getUser(), info.getCurrentOrg(), info.getOrgs(), uSystem);
|
|
|
|
|
// 登录信息存放Session。这里可能是学校管理员
|
|
|
|
|
webPlatformService.setUserInfoToSessionByIdentity(info.getUser());
|
|
|
|
|
}
|
|
|
|
|
return JsonResult.success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// @PostMapping("/login.json")
|
|
|
|
|
@ResponseBody
|
|
|
|
|
public JsonResult login2(String code, String password) {
|
|
|
|
|
UserLoginInfo info = null;
|
|
|
|
|
try {
|
|
|
|
|
info = userService.login(code, password);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
return JsonResult.failMessage(e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
CoreUser user = info.getUser();
|
|
|
|
|
|
|
|
|
|
CoreOrg currentOrg = info.getOrgs().get(0);
|
|
|
|
|
for (CoreOrg org : info.getOrgs()) {
|
|
|
|
|
if (org.getId().equals(user.getOrgId())) {
|
|
|
|
|
currentOrg = org;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
tokenSessionMap.put(studentToken, new Object[]{user, info.getCurrentOrg(), info.getOrgs(), uSystem});
|
|
|
|
|
// 登录信息存放Session
|
|
|
|
|
webPlatformService.setUserInfoToSessionByIdentity(info.getUser());
|
|
|
|
|
platformService.setLoginUser(info.getUser(), info.getCurrentOrg(), info.getOrgs(), uSystem);
|
|
|
|
|
return JsonResult.success(keyId);
|
|
|
|
|
}
|
|
|
|
|
} break;
|
|
|
|
|
}
|
|
|
|
|
info.setCurrentOrg(currentOrg);
|
|
|
|
|
|
|
|
|
|
// 保存用户信息到Session中
|
|
|
|
|
this.platformService.setLoginUser(info.getUser(), info.getCurrentOrg(), info.getOrgs(), null);
|
|
|
|
|
return JsonResult.success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|