main
HuangHai 3 months ago
parent 6fa4d8548f
commit 520d2feebc

@ -42,13 +42,13 @@ public class LoginPersonController extends Controller {
String checkCodeKey = ""; String checkCodeKey = "";
//万能验证码:dsideal //万能验证码:dsideal
if (!captcha.equals("dsideal")) { if (!captcha.equals("dsideal")) {
if (SessionKit.get(getRequest(), getResponse(), "captcha") == null) { if (CookieUtil.getValue(getRequest(), "captcha") == null) {
resultJson.put("success", false); resultJson.put("success", false);
resultJson.put("msg", "在浏览器会话中没有检查到验证码,你的行为将会记录!"); resultJson.put("msg", "在浏览器会话中没有检查到验证码,你的行为将会记录!");
renderJson(resultJson); renderJson(resultJson);
return; return;
} }
String memory_captcha = SessionKit.get(getRequest(), getResponse(), "captcha").toLowerCase(); String memory_captcha = Objects.requireNonNull(CookieUtil.getValue(getRequest(), "captcha")).toLowerCase();
//验证码错误次数 //验证码错误次数
checkCodeKey = "Yzm_error_" + username; checkCodeKey = "Yzm_error_" + username;
int CheckCodeErrCnt = 4; //最多允许错几次 4+1 int CheckCodeErrCnt = 4; //最多允许错几次 4+1
@ -186,7 +186,7 @@ public class LoginPersonController extends Controller {
*/ */
@Before(POST.class) @Before(POST.class)
@EmptyInterface({"username", "password", "platform"}) @EmptyInterface({"username", "password", "platform"})
public void doLogin_Internal(String username, String password,String platform) { public void doLogin_Internal(String username, String password, String platform) {
JSONObject resultJson = new JSONObject(); JSONObject resultJson = new JSONObject();
//检查缓存中此账号错误了几次 //检查缓存中此账号错误了几次
@ -283,7 +283,8 @@ public class LoginPersonController extends Controller {
*/ */
@Before({GET.class}) @Before({GET.class})
public void logout() { public void logout() {
SessionKit.clear(getRequest(), getResponse()); //SessionKit.clear(getRequest(), getResponse());
//TODO: 登出功能需要完善,目前只重定向到登录页面
redirect("/plogin.html"); redirect("/plogin.html");
} }
@ -298,7 +299,7 @@ public class LoginPersonController extends Controller {
public void ResetPwd(String person_id) { public void ResetPwd(String person_id) {
//修改密码 //修改密码
Record rPerson = JwtUtil.getPersonInfo(getRequest()); Record rPerson = JwtUtil.getPersonInfo(getRequest());
String operator = rPerson.getStr("person_id"); String operator = rPerson.getStr("person_id");
//客户端ip_address //客户端ip_address
String ip_address = IpUtil.getIpAddr(getRequest()); String ip_address = IpUtil.getIpAddr(getRequest());
lm.changePwd(operator, ip_address, "123456", person_id); lm.changePwd(operator, ip_address, "123456", person_id);
@ -315,7 +316,8 @@ String operator = rPerson.getStr("person_id");
@EmptyInterface({"old_pwd", "new_pwd"}) @EmptyInterface({"old_pwd", "new_pwd"})
@LengthInterface({"new_pwd,6,18"}) @LengthInterface({"new_pwd,6,18"})
public void changePwd(String old_pwd, String new_pwd) { public void changePwd(String old_pwd, String new_pwd) {
String person_id = SessionKit.get(getRequest(), getResponse(), "person_id"); Record rPerson = JwtUtil.getPersonInfo(getRequest());
String person_id = rPerson.getStr("person_id");
//客户端ip_address //客户端ip_address
String ip_address = IpUtil.getIpAddr(getRequest()); String ip_address = IpUtil.getIpAddr(getRequest());
@ -341,7 +343,8 @@ String operator = rPerson.getStr("person_id");
@Before({GET.class}) @Before({GET.class})
public void getLoginPersonInfo() { public void getLoginPersonInfo() {
JSONObject resultJson = new JSONObject(); JSONObject resultJson = new JSONObject();
String personId = SessionKit.get(getRequest(), getResponse(), "person_id"); Record rPerson = JwtUtil.getPersonInfo(getRequest());
String personId = rPerson.getStr("person_id");
Record record = lm.getLoginInfoByPersonId(personId); Record record = lm.getLoginInfoByPersonId(personId);
if (record == null) { if (record == null) {
resultJson.put("success", false); resultJson.put("success", false);
@ -519,7 +522,7 @@ String operator = rPerson.getStr("person_id");
// 重新生成code // 重新生成code
captcha.createCode(); captcha.createCode();
//写入session //写入session
SessionKit.set(getRequest(), getResponse(), "captcha", captcha.getCode()); CookieUtil.set(getResponse(), "captcha", captcha.getCode(), true, false);
// 将内存中的图片通过流动形式输出到客户端 // 将内存中的图片通过流动形式输出到客户端
captcha.write(response.getOutputStream()); captcha.write(response.getOutputStream());
} catch (Exception e) { } catch (Exception e) {
@ -538,7 +541,8 @@ String operator = rPerson.getStr("person_id");
@Before(POST.class) @Before(POST.class)
public void updateTelephoneEmail(String telephone, String email) { public void updateTelephoneEmail(String telephone, String email) {
String personId = SessionKit.get(getRequest(), getResponse(), "person_id"); Record rPerson = JwtUtil.getPersonInfo(getRequest());
String personId = rPerson.getStr("person_id");
lm.updateTelephoneEmail(personId, telephone, email); lm.updateTelephoneEmail(personId, telephone, email);
Kv kv = Kv.create(); Kv kv = Kv.create();
kv.set("success", true); kv.set("success", true);

@ -79,7 +79,7 @@ public class TeacherYdController extends Controller {
public void updateTeacherStatus(String person_id, String status_code) { public void updateTeacherStatus(String person_id, String status_code) {
//操作人 //操作人
Record rPerson = JwtUtil.getPersonInfo(getRequest()); Record rPerson = JwtUtil.getPersonInfo(getRequest());
String operator = rPerson.getStr("person_id"); String operator = rPerson.getStr("person_id");
//客户端ip_address //客户端ip_address
String ip_address = IpUtil.getIpAddr(getRequest()); String ip_address = IpUtil.getIpAddr(getRequest());
@ -143,7 +143,7 @@ String operator = rPerson.getStr("person_id");
//操作人 //操作人
Record rPerson = JwtUtil.getPersonInfo(getRequest()); Record rPerson = JwtUtil.getPersonInfo(getRequest());
String operator = rPerson.getStr("person_id"); String operator = rPerson.getStr("person_id");
//客户端ip_address //客户端ip_address
String ip_address = IpUtil.getIpAddr(getRequest()); String ip_address = IpUtil.getIpAddr(getRequest());
@ -205,7 +205,7 @@ String operator = rPerson.getStr("person_id");
} }
//操作人 //操作人
Record rPerson = JwtUtil.getPersonInfo(getRequest()); Record rPerson = JwtUtil.getPersonInfo(getRequest());
String operator = rPerson.getStr("person_id"); String operator = rPerson.getStr("person_id");
//客户端ip_address //客户端ip_address
String ip_address = IpUtil.getIpAddr(getRequest()); String ip_address = IpUtil.getIpAddr(getRequest());
@ -232,7 +232,7 @@ String operator = rPerson.getStr("person_id");
//当前登录人员所在单位 //当前登录人员所在单位
Record rPerson = JwtUtil.getPersonInfo(getRequest()); Record rPerson = JwtUtil.getPersonInfo(getRequest());
String person_id = rPerson.getStr("person_id"); String person_id = rPerson.getStr("person_id");
BaseModel bm = new BaseModel(); BaseModel bm = new BaseModel();
String bureau_id = bm.getPersonInfo(person_id).getStr("bureau_id"); String bureau_id = bm.getPersonInfo(person_id).getStr("bureau_id");
Page<Record> rs = model.getTeacherTransferEchoList(page, limit, bureau_id, person_name); Page<Record> rs = model.getTeacherTransferEchoList(page, limit, bureau_id, person_name);
@ -252,7 +252,7 @@ String person_id = rPerson.getStr("person_id");
public void getTeacherTransferInfoById(int id) { public void getTeacherTransferInfoById(int id) {
//尝试修改一下阅读状态 //尝试修改一下阅读状态
Record rPerson = JwtUtil.getPersonInfo(getRequest()); Record rPerson = JwtUtil.getPersonInfo(getRequest());
String person_id = rPerson.getStr("person_id"); String person_id = rPerson.getStr("person_id");
boolean result = model.ChangeTransferApplyReadStatus(id, person_id); boolean result = model.ChangeTransferApplyReadStatus(id, person_id);
if (!result) { if (!result) {
renderJson(CommonUtil.returnMessageJson(false, "处理阅读状态失败!!")); renderJson(CommonUtil.returnMessageJson(false, "处理阅读状态失败!!"));
@ -280,8 +280,9 @@ String person_id = rPerson.getStr("person_id");
} }
Record rPerson = JwtUtil.getPersonInfo(getRequest()); Record rPerson = JwtUtil.getPersonInfo(getRequest());
String source_bureau_id = records.getFirst().getStr("source_bureau_id"); String source_bureau_id = records.getFirst().getStr("source_bureau_id");
String personId = rPerson.getStr("person_id");; String personId = rPerson.getStr("person_id");
String identity_id = rPerson.getStr("identity_id"); ;
String identity_id = rPerson.getStr("identity_id");
LoginPersonModel _loginPersonModel = new LoginPersonModel(); LoginPersonModel _loginPersonModel = new LoginPersonModel();
Record obj = _loginPersonModel.getLoginInfoByPersonId(personId); Record obj = _loginPersonModel.getLoginInfoByPersonId(personId);
if (identity_id != null && identity_id.equals("4") && !obj.get("bureau_id").equals(source_bureau_id)) { if (identity_id != null && identity_id.equals("4") && !obj.get("bureau_id").equals(source_bureau_id)) {
@ -302,8 +303,7 @@ String person_id = rPerson.getStr("person_id");
} }
//4、删除它 //4、删除它
//操作人 //操作人
Record rPerson = JwtUtil.getPersonInfo(getRequest()); String operator = rPerson.getStr("person_id");
String operator = rPerson.getStr("person_id");
//客户端ip_address //客户端ip_address
String ip_address = IpUtil.getIpAddr(getRequest()); String ip_address = IpUtil.getIpAddr(getRequest());
model.deleteTransferInfoById(id, operator, ip_address); model.deleteTransferInfoById(id, operator, ip_address);
@ -313,7 +313,6 @@ String operator = rPerson.getStr("person_id");
/** /**
* () * ()
*
*/ */
@Before({GET.class}) @Before({GET.class})
@ -322,7 +321,7 @@ String operator = rPerson.getStr("person_id");
public void getNewTeacherTransferApplyCount() { public void getNewTeacherTransferApplyCount() {
//当前登录人员所在单位 //当前登录人员所在单位
Record rPerson = JwtUtil.getPersonInfo(getRequest()); Record rPerson = JwtUtil.getPersonInfo(getRequest());
String person_id = rPerson.getStr("person_id"); String person_id = rPerson.getStr("person_id");
BaseModel bm = new BaseModel(); BaseModel bm = new BaseModel();
String bureau_id = bm.getPersonInfo(person_id).getStr("bureau_id"); String bureau_id = bm.getPersonInfo(person_id).getStr("bureau_id");
int count = model.getNewTeacherTransferApplyCount(bureau_id); int count = model.getNewTeacherTransferApplyCount(bureau_id);
@ -333,7 +332,6 @@ String person_id = rPerson.getStr("person_id");
/** /**
* () * ()
*
*/ */
@Before({GET.class}) @Before({GET.class})
@ -342,7 +340,7 @@ String person_id = rPerson.getStr("person_id");
public void getNewTeacherTransferEchoCount() { public void getNewTeacherTransferEchoCount() {
//当前登录人员所在单位 //当前登录人员所在单位
Record rPerson = JwtUtil.getPersonInfo(getRequest()); Record rPerson = JwtUtil.getPersonInfo(getRequest());
String person_id = rPerson.getStr("person_id"); String person_id = rPerson.getStr("person_id");
BaseModel bm = new BaseModel(); BaseModel bm = new BaseModel();
String bureau_id = bm.getPersonInfo(person_id).getStr("bureau_id"); String bureau_id = bm.getPersonInfo(person_id).getStr("bureau_id");
int count = model.getNewTeacherTransferEchoCount(bureau_id); int count = model.getNewTeacherTransferEchoCount(bureau_id);

@ -0,0 +1,56 @@
package com.dsideal.dsBase.Util;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class CookieUtil {
// 默认缓存时间,单位/秒, 2H
private static final int COOKIE_MAX_AGE = 60 * 60 * 2;
// 保存路径,根路径
private static final String COOKIE_PATH = "/";
public static String getValue(HttpServletRequest request, String key) {
Cookie cookie = get(request, key);
if (cookie != null) {
return cookie.getValue();
}
return null;
}
private static Cookie get(HttpServletRequest request, String key) {
Cookie[] arr_cookie = request.getCookies();
if (arr_cookie != null && arr_cookie.length > 0) {
for (Cookie cookie : arr_cookie) {
if (cookie.getName().equals(key)) {
return cookie;
}
}
}
return null;
}
public static void set(HttpServletResponse response, String key, String value, boolean ifRemember,boolean isHttpOnly) {
int age = ifRemember ? COOKIE_MAX_AGE : -1;
set(response, key, value, null, COOKIE_PATH, age, isHttpOnly);
}
private static void set(HttpServletResponse response, String key, String value, String domain, String path, int maxAge, boolean isHttpOnly) {
Cookie cookie = new Cookie(key, value);
if (domain != null) {
cookie.setDomain(domain);
}
cookie.setPath(path);
cookie.setMaxAge(maxAge);
cookie.setHttpOnly(isHttpOnly);
response.addCookie(cookie);
}
public static void remove(HttpServletRequest request, HttpServletResponse response, String key) {
Cookie cookie = get(request, key);
if (cookie != null) {
set(response, key, "", null, COOKIE_PATH, 0, true);
}
}
}
Loading…
Cancel
Save