Skip to content

Commit be885ec

Browse files
committed
可配置是否允许多端登录
1 parent 52cfc26 commit be885ec

File tree

7 files changed

+6988
-2
lines changed

7 files changed

+6988
-2
lines changed

api/jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/controller/LoginController.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.jeecg.modules.system.service.ISysUserService;
2727
import org.jeecg.modules.system.util.RandImageUtil;
2828
import org.springframework.beans.factory.annotation.Autowired;
29+
import org.springframework.beans.factory.annotation.Value;
2930
import org.springframework.web.bind.annotation.*;
3031

3132
import javax.servlet.http.HttpServletRequest;
@@ -54,6 +55,9 @@ public class LoginController {
5455
@Autowired
5556
private ISysDictService sysDictService;
5657

58+
@Value("${jeecg.multiLogin}")
59+
private Boolean multiLogin;
60+
5761
// private static final String BASE_CHECK_CODES = "qwertyuiplkjhgfdsazxcvbnmQWERTYUPLKJHGFDSAZXCVBNM1234567890";
5862
private static final String BASE_CHECK_CODES = "1234567890";
5963

@@ -126,6 +130,7 @@ public Result<Object> logout(HttpServletRequest request,HttpServletResponse resp
126130
if(sysUser!=null) {
127131
sysBaseAPI.addLog("用户名: "+sysUser.getRealname()+",退出成功!", CommonConstant.LOG_TYPE_1, null);
128132
log.info(" 用户名: "+sysUser.getRealname()+",退出成功! ");
133+
redisUtil.del(CommonConstant.PREFIX_USER_TOKEN + username);
129134
//清空用户登录Token缓存
130135
redisUtil.del(CommonConstant.PREFIX_USER_TOKEN + token);
131136
//清空用户登录Shiro权限缓存
@@ -340,12 +345,25 @@ public Result<JSONObject> phoneLogin(@RequestBody JSONObject jsonObject) {
340345
private Result<JSONObject> userInfo(SysUser sysUser, Result<JSONObject> result) {
341346
String syspassword = sysUser.getPassword();
342347
String username = sysUser.getUsername();
348+
349+
//是否允许多端登录
350+
if (!multiLogin){
351+
String oldToken = String.valueOf(redisUtil.get(CommonConstant.PREFIX_USER_TOKEN + username));
352+
if (oConvertUtils.isNotEmpty(oldToken)){
353+
redisUtil.del(CommonConstant.PREFIX_USER_TOKEN + oldToken);
354+
}
355+
}
356+
343357
// 生成token
344358
String token = JwtUtil.sign(username, syspassword);
345359
// 设置token缓存有效时间
346360
redisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, token);
347361
redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, JwtUtil.EXPIRE_TIME*2 / 1000);
348362

363+
//记录本次登录token
364+
redisUtil.set(CommonConstant.PREFIX_USER_TOKEN + username, token);
365+
redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + username, JwtUtil.EXPIRE_TIME*2 / 1000);
366+
349367
// 获取用户部门信息
350368
JSONObject obj = new JSONObject();
351369
List<SysDepart> departs = sysDepartService.queryUserDeparts(sysUser.getId());

api/jeecg-boot-module-system/src/main/resources/application-dev.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ mybatis-plus:
168168
call-setters-on-nulls: true
169169
#jeecg专用配置
170170
jeecg :
171+
# 是否允许多端登录
172+
multiLogin: false
171173
# 站点域名
172174
domain: http://localhost
173175
# 本地:local\Minio:minio\阿里云:alioss

api/jeecg-boot-module-system/src/main/resources/application-prod.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ mybatis-plus:
168168
call-setters-on-nulls: true
169169
#jeecg专用配置
170170
jeecg :
171+
# 是否允许多端登录
172+
multiLogin: false
171173
# 站点域名
172174
domain: http://open.teaching.vip
173175
# 本地:local\Minio:minio\阿里云:alioss

api/jeecg-boot-module-system/src/main/resources/application-test.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@ mybatis-plus:
168168
call-setters-on-nulls: true
169169
#jeecg专用配置
170170
jeecg :
171+
# 是否允许多端登录
172+
multiLogin: false
173+
# 站点域名
174+
domain: http://open.teaching.vip
171175
# 本地:local\Minio:minio\阿里云:alioss
172176
uploadType: local
173177
path :

web/public/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<meta name="viewport" content="width=device-width,initial-scale=1.0">
88
<title>Teaching</title>
99
<link rel="icon" href="<%= BASE_URL %>logo.png">
10-
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-polyfill/7.2.5/polyfill.js"></script>
10+
<script src="/js/polyfill.js"></script>
1111
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-155190299-2"></script>
1212
<script src="/js/common.js"></script>
1313
<style>

web/public/js/common.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,5 +104,12 @@ function dataURLtoBlob(dataurl) {
104104
window.dataLayer = window.dataLayer || [];
105105
function gtag(){dataLayer.push(arguments);}
106106
gtag('js', new Date());
107+
gtag('config', 'UA-155190299-2');
107108

108-
gtag('config', 'UA-155190299-2');
109+
var _hmt = _hmt || [];
110+
(function() {
111+
var hm = document.createElement("script");
112+
hm.src = "https://hm.baidu.com/hm.js?5701500c2c4326d51b2652ee8426452e";
113+
var s = document.getElementsByTagName("script")[0];
114+
s.parentNode.insertBefore(hm, s);
115+
})();

0 commit comments

Comments
 (0)