修改用户信息,在线用户需要重新登录

This commit is contained in:
jiangzeyin 2019-04-15 13:35:09 +08:00
parent 1f1bcc8a98
commit 8ca743ee71
12 changed files with 107 additions and 58 deletions

View File

@ -15,6 +15,7 @@
9. 首页进程监听表格显示端口号(感谢@洋芋)
10. 保存时检查Oss信息是否正确
11. Jpom管理命令新增判断`JAVA_HOME`环境变量
12. 修改用户信息,在线用户需要重新登录
### 解决BUG、优化功能

View File

@ -4,16 +4,23 @@ import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.servlet.ServletUtil;
import cn.jiangzeyin.common.JsonMessage;
import cn.jiangzeyin.common.interceptor.BaseInterceptor;
import cn.jiangzeyin.common.interceptor.InterceptorPattens;
import cn.jiangzeyin.common.spring.SpringUtil;
import cn.keepbx.jpom.common.BaseController;
import cn.keepbx.jpom.model.UserModel;
import cn.keepbx.jpom.service.user.UserService;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
/**
* 登录拦截器
@ -38,7 +45,20 @@ public class LoginInterceptor extends BaseInterceptor {
if (notLogin == null) {
UserModel user = (UserModel) session.getAttribute(SESSION_NAME);
if (user == null) {
response.sendRedirect(getHeaderProxyPath(request) + "/login.html");
this.responseLogin(request, response, handlerMethod);
return false;
}
// 用户信息
UserService userService = SpringUtil.getBean(UserService.class);
UserModel newUser = userService.getItem(user.getId());
if (newUser == null) {
// 用户被删除
this.responseLogin(request, response, handlerMethod);
return false;
}
if (user.getModifyTime() != newUser.getModifyTime()) {
// 被修改过
this.responseLogin(request, response, handlerMethod);
return false;
}
}
@ -47,6 +67,26 @@ public class LoginInterceptor extends BaseInterceptor {
return true;
}
/**
* 提示登录
*
* @param request req
* @param response res
* @param handlerMethod 方法
* @throws IOException 异常
*/
private void responseLogin(HttpServletRequest request, HttpServletResponse response, HandlerMethod handlerMethod) throws IOException {
ResponseBody responseBody = handlerMethod.getMethodAnnotation(ResponseBody.class);
if (responseBody == null) {
RestController restController = handlerMethod.getBeanType().getAnnotation(RestController.class);
if (restController == null) {
response.sendRedirect(getHeaderProxyPath(request) + "/login.html");
return;
}
}
ServletUtil.write(response, JsonMessage.getString(800, "登录信息已失效,重新登录"), MediaType.APPLICATION_JSON_UTF8_VALUE);
}
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
super.postHandle(request, response, handler, modelAndView);

View File

@ -1,4 +1,6 @@
/**
* controller 控制器
* <p>
* The MIT License(MIT)
* <p>
* Copyright(c) 2019 码之科技工作室
@ -20,7 +22,6 @@
* IN AN ACTION OF CONTRACT,TORT OR OTHERWISE,ARISING FROM,OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* <p>
* controller 控制器
*
* @author jiangzeyin
*/

View File

@ -1,5 +1,6 @@
package cn.keepbx.jpom.controller.user;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import cn.jiangzeyin.common.DefaultSystemLog;
import cn.jiangzeyin.common.JsonMessage;
@ -248,6 +249,8 @@ public class UserInfoController extends BaseController {
if (msg != null) {
return msg;
}
// 记录修改时间如果在线用户线退出
userModel.setModifyTime(DateUtil.currentSeconds());
boolean b = userService.updateItem(userModel);
if (b) {
return JsonMessage.getString(200, "修改成功");

View File

@ -67,6 +67,10 @@ public class UserModel extends BaseModel {
* 删除文件权限
*/
private boolean deleteFile;
/**
* 记录最后修改时间
*/
private long modifyTime;
/**
* 获取是否有上传文件的权限
@ -230,6 +234,8 @@ public class UserModel extends BaseModel {
public void setPassword(String password) {
this.password = password;
// 记录修改时间如果在线用户线退出
this.setModifyTime(DateUtil.current(false));
}
public String getUserMd5Key() {
@ -281,4 +287,11 @@ public class UserModel extends BaseModel {
return "demo".equals(getId());
}
public long getModifyTime() {
return modifyTime;
}
public void setModifyTime(long modifyTime) {
this.modifyTime = modifyTime;
}
}

View File

@ -63,7 +63,7 @@
}
## 带loading 效果的网络请求
function loadingAjax(data) {
function loadingAjax(data, closeLoading) {
var success = data.success;
delete data.success;
var error = data.error;
@ -73,12 +73,22 @@
type: 'POST',
dataType: 'json',
beforeSend: function () {
index = layer.load(1, {
shade: [0.3, '#fff']
});
if (closeLoading !== true) {
index = layer.load(1, {
shade: [0.3, '#fff']
});
}
},
success: function (data) {
layer.close(index);
if (data.code == 800) {
## 用户信息失效
layer.msg(data.msg);
setTimeout(function () {
top.location.reload();
}, 1500);
return;
}
success && success(data);
},
error: function () {
@ -89,4 +99,8 @@
$.extend(defData, data);
$.ajax(defData);
}
function silentAjax(data) {
loadingAjax(data, true);
}
</script>

View File

@ -75,11 +75,12 @@
<dl class="layui-nav-child">
<dd><a href="javascript:;" op="updatePwd">修改密码</a></dd>
<dd><a href="javascript:;" op="updateName">修改昵称</a></dd>
<dd><a href="javascript:;" op="exit">退出登录</a></dd>
</dl>
</li>
<li class="layui-nav-item" id="li-exit">
<a href="javascript:;">退出</a>
</li>
## <li class="layui-nav-item" id="li-exit">
##
## </li>
</ul>
</div>
<div class="layui-side layui-bg-black">
@ -206,6 +207,13 @@
}
});
});
} else if ('exit' == op) {
layer.confirm('确定退出系统?', {
'title': '系统提示'
}, function (index) {
window.location.href = "./logout";
layer.close(index);
})
}
});
@ -252,16 +260,6 @@
});
return false;
});
// 退出系统
$('#li-exit').click(function () {
layer.confirm('确定退出系统?', {
'title': '系统提示'
}, function (index) {
window.location.href = "./logout";
layer.close(index);
})
});
}
</script>
</html>

View File

@ -240,10 +240,8 @@
}
function reqLogSize() {
$.ajax({
silentAjax({
url: './log/logSize',
type: 'POST',
dataType: 'json',
data: {
id: "$!projectInfo.id"
},
@ -255,11 +253,6 @@
$("#resetLog").hide();
layer.msg(data.msg);
}
},
error: function () {
loopLog = false;
clearInterval(loopLogTime);
layer.alert("日志监听失败");
}
});
}

View File

@ -243,10 +243,8 @@
return;
}
var lib = wVal + $("#projectEnd").text();
$.ajax({
silentAjax({
url: './judge_lib.json',
type: 'POST',
dataType: 'json',
data: {
id: "#if($item)$!item.id#else#end",
newLib: lib
@ -257,9 +255,6 @@
} else {
$("#tipMsg").text(data.msg).parent().show();
}
},
error: function (err) {
layer.msg('检查路径失败,请稍后再试');
}
});
}

View File

@ -150,10 +150,8 @@
if (ids.length <= 0) {
return
}
$.ajax({
silentAjax({
url: './getProjectPort',
type: 'POST',
dataType: 'json',
data: {
ids: JSON.stringify(ids)
},
@ -164,9 +162,6 @@
$("span[p-Id='" + key + "']").text(data.data[key].port).attr("title", "端口:" + data.data[key].port + " 进程id:" + data.data[key].pid);
}
}
},
error: function (err) {
}
});
}

View File

@ -126,10 +126,8 @@
table.render(config);
function loadFirstEcharts() {
$.ajax({
silentAjax({
url: './getTop',
type: 'POST',
dataType: 'json',
success: function (data) {
if (200 == data.code) {
if (data.data) {
@ -139,19 +137,13 @@
} else {
layer.alert(data.msg);
}
},
error: function (err) {
layer.alert("监控信息异常!");
}
});
}
function loadProcessList() {
$.ajax({
silentAjax({
url: './processList',
type: 'POST',
dataType: 'json',
async: true,
success: function (data) {
if (200 == data.code) {
if (data.data) {
@ -161,9 +153,6 @@
} else {
layer.alert(data.msg);
}
},
error: function (err) {
layer.alert("监控信息异常!");
}
});
}

View File

@ -1,3 +1,5 @@
import cn.hutool.core.io.FileUtil;
import java.io.File;
import java.io.IOException;
@ -6,13 +8,18 @@ import java.io.IOException;
*/
public class TestFile {
public static void main(String[] args) throws IOException {
File file = new File("C:/WINDOWS/system32/s/s");
System.out.println(file.toPath().startsWith(new File("C:/Windows/System32/s/S").toPath()));
// System.out.println(file());
// File file = new File("C:/WINDOWS/system32/s/s");
// System.out.println(file.toPath().startsWith(new File("C:/Windows/System32/s/S").toPath()));
//// System.out.println(file());
//
//
// File file1 = new File("D:/keystore.p12");
// System.out.println(file1.exists() && file1.isFile());
File file1 = new File("D:/keystore.p12");
System.out.println(file1.exists() && file1.isFile());
System.out.println(FileUtil.loopFiles("D:\\sss"));
FileUtil.cleanEmpty(new File("D:\\sss"));
System.out.println("----------------------------------------");
System.out.println(FileUtil.loopFiles("D:\\sss"));
}