修改token冲突及 自动登录

This commit is contained in:
haozq 2025-12-29 10:30:44 +08:00
parent 45be3a1356
commit d806602343
9 changed files with 92 additions and 26 deletions

View File

@ -77,7 +77,6 @@ public class UserDetailsServiceImpl implements UserDetailsService {
throw new AuthenticationCredentialsNotFoundException("用户名/密码错误!"); throw new AuthenticationCredentialsNotFoundException("用户名/密码错误!");
} }
long num=0L; long num=0L;
try{ try{
num=redisUtil.countKeys();//在线用户 num=redisUtil.countKeys();//在线用户

View File

@ -1,11 +1,11 @@
server.port=11998 server.port=11998
server.servlet.context-path=/gzDigitalSignage server.servlet.context-path=/gzDigitalSignage
#spring.datasource.url=jdbc:mysql://192.168.0.16:4419/gz_digital_signage?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false spring.datasource.url=jdbc:mysql://192.168.0.16:4419/gz_digital_signage?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false
#spring.datasource.username=root
#spring.datasource.password=Bonus@admin123!
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/gz_digital_signage?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false
spring.datasource.username=root spring.datasource.username=root
spring.datasource.password=ccw1998@yyt1999 spring.datasource.password=Bonus@admin123!
#spring.datasource.url=jdbc:mysql://127.0.0.1:3306/gz_digital_signage?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false
#spring.datasource.username=root
#spring.datasource.password=ccw1998@yyt1999
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.max-idle=10 spring.datasource.max-idle=10
spring.datasource.max-wait=60000 spring.datasource.max-wait=60000
@ -25,6 +25,8 @@ mybatis.type-aliases-package=com.bonus.digitalSignage.*.vo
spring.redis.host=127.0.0.1 spring.redis.host=127.0.0.1
spring.redis.port=6379 spring.redis.port=6379
spring.redis.database=6
# \u65E5\u5FD7 # \u65E5\u5FD7
logging.config=classpath:logback-boot.xml logging.config=classpath:logback-boot.xml

View File

@ -1,7 +1,7 @@
$.ajaxSetup({ $.ajaxSetup({
cache : false, cache : false,
headers : { headers : {
"token" : localStorage.getItem("token") "token" : localStorage.getItem("gds-token")
}, },
error : function(xhr, textStatus, errorThrown) { error : function(xhr, textStatus, errorThrown) {
var msg = xhr.responseText; var msg = xhr.responseText;
@ -11,7 +11,7 @@ $.ajaxSetup({
if (code == 400) { if (code == 400) {
layer.msg(message); layer.msg(message);
} else if (code == 401) { } else if (code == 401) {
localStorage.removeItem("token"); localStorage.removeItem("gds-token")
location.href = '/login.html'; location.href = '/login.html';
} else if (code == 403) { } else if (code == 403) {
console.log("未授权:" + message); console.log("未授权:" + message);

View File

@ -11,7 +11,33 @@ document.addEventListener('DOMContentLoaded', function() {
if (top != self) { if (top != self) {
parent.location.href = '/digitalSignage/login.html'; parent.location.href = '/digitalSignage/login.html';
} }
var token = localStorage.getItem("token");
//自动登录
window.onload = function() {
//获取浏览器路径
let hrefUrl = window.location.href;
const url = new URL(hrefUrl);
const urlParam = new URLSearchParams(url.search);
//解析路径参数
const params = urlParam.get('params');
if(params){
//对参数进行解密
const jiemi =bnsCloudDecrypt(params);
//解密参数继续解析
const logingParam = new URLSearchParams(jiemi);
//获取账号密码
const username = logingParam.get('username');
const password = logingParam.get('password');
if(username && password){
//自己系统登录的方法
authLogin(username,password);
}
}else{
console.log("无自动登录参数");
}
};
var token = localStorage.getItem("gds-token");
if (token != null && token.trim().length != 0) { if (token != null && token.trim().length != 0) {
$.ajax({ $.ajax({
type: 'get', type: 'get',
@ -26,15 +52,13 @@ if (token != null && token.trim().length != 0) {
var code = response.code; var code = response.code;
var message = response.message; var message = response.message;
if (code == 401) { if (code == 401) {
localStorage.removeItem("token"); localStorage.removeItem("gds-token");
} }
} }
}); });
} }
function login(obj) { function login(obj) {
$(obj).attr("disabled", true); $(obj).attr("disabled", true);
var username = $.trim($('#username').val()); var username = $.trim($('#username').val());
var password = $.trim($('#password').val()); var password = $.trim($('#password').val());
if (username == "" || password == "") { if (username == "" || password == "") {
@ -50,7 +74,7 @@ function login(obj) {
_csrf: $('#csrfToken').val() _csrf: $('#csrfToken').val()
}, },
success: function (data) { success: function (data) {
localStorage.setItem("token", data.token); localStorage.setItem("gds-token", data.token);
location.href = ctxPath + '/index.html'; location.href = ctxPath + '/index.html';
}, },
error: function (xhr, textStatus, errorThrown) { error: function (xhr, textStatus, errorThrown) {
@ -62,4 +86,27 @@ function login(obj) {
}); });
} }
}
function authLogin(username,password) {
$.ajax({
type: 'post',
url: ctxPath + '/login',
data: {
username: encryptCBC(username),
password: encryptCBC(password),
_csrf: $('#csrfToken').val()
},
success: function (data) {
localStorage.setItem("gds-token", data.token);
location.href = ctxPath + '/index.html';
},
error: function (xhr, textStatus, errorThrown) {
var msg = xhr.responseText;
var response = JSON.parse(msg);
$("#info").html(response.message);
$(obj).attr("disabled", false);
}
});
} }

View File

@ -60,7 +60,7 @@ function initMenu(){
var status = response.status; var status = response.status;
var code = response.code; var code = response.code;
if (status == 401 || code == 401) { if (status == 401 || code == 401) {
localStorage.removeItem("token"); localStorage.removeItem("gds-token");
} }
} }
}); });
@ -70,7 +70,7 @@ function initsy() {
var $tabsTitle = $tabs.find('.layui-nav-item a'); var $tabsTitle = $tabs.find('.layui-nav-item a');
$.each($tabsTitle,function(idx, ele){ $.each($tabsTitle,function(idx, ele){
var id=$(ele).attr("lay-id"); var id=$(ele).attr("lay-id");
$("#sy").attr("src","pages/home/home.html?token="+localStorage.getItem("token")); $("#sy").attr("src","pages/home/home.html?token="+localStorage.getItem("gds-token"));
}) })
} }
function setChild(parentElement, child){ function setChild(parentElement, child){
@ -148,7 +148,7 @@ function logout(){
_csrf: $('#csrfToken').val() _csrf: $('#csrfToken').val()
}, },
success : function(data) { success : function(data) {
localStorage.removeItem("token"); localStorage.removeItem("gds-token")
location.href= ctxPath + '/login.html'; location.href= ctxPath + '/login.html';
} }
}); });
@ -183,7 +183,7 @@ var element ;
//新增一个Tab项 //新增一个Tab项
element.tabAdd('admin-tab', { element.tabAdd('admin-tab', {
title: title, title: title,
content: '<iframe src="' + $(this).attr('data-url')+'?token='+localStorage.getItem("token") + '"></iframe>', content: '<iframe src="' + $(this).attr('data-url')+'?token='+localStorage.getItem("gds-token") + '"></iframe>',
id: lay_id id: lay_id
}); });
element.tabChange("admin-tab", lay_id); element.tabChange("admin-tab", lay_id);
@ -277,7 +277,7 @@ function parentOpen(url,lay_id,title){
} }
element.tabAdd('admin-tab', { element.tabAdd('admin-tab', {
title: title, title: title,
content: '<iframe src="' + url+'?token='+localStorage.getItem("token") + '"></iframe>', content: '<iframe src="' + url+'?token='+localStorage.getItem("gds-token") + '"></iframe>',
id: lay_id id: lay_id
}); });

View File

@ -68,4 +68,22 @@ function dateFtt(fmt, date) { //author: meizz
if(new RegExp("(" + k + ")").test(fmt)) if(new RegExp("(" + k + ")").test(fmt))
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length))); fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
return fmt; return fmt;
} }
/**
* @param {Object} word解密
*/
function bnsCloudDecrypt(word){
var key = CryptoJS.enc.Utf8.parse("bonus@cloud@2025");
var decrypt = CryptoJS.AES.decrypt(word, key, {mode:CryptoJS.mode.ECB,padding: CryptoJS.pad.Pkcs7});
return CryptoJS.enc.Utf8.stringify(decrypt).toString();
}
/**
* @param {Object} word加密
*/
function bnsCloudEncrypt(word){
var key = CryptoJS.enc.Utf8.parse("bonus@cloud@2025");
var srcs = CryptoJS.enc.Utf8.parse(word);
var encrypted = CryptoJS.AES.encrypt(srcs, key, {mode:CryptoJS.mode.ECB,padding: CryptoJS.pad.Pkcs7});
return encrypted.toString();
}

View File

@ -6,12 +6,12 @@ var url=window.location.href;
let test_url="http://192.168.0.14:11998/gzDigitalSignage"; let test_url="http://192.168.0.14:11998/gzDigitalSignage";
let dev_url="http://36.33.26.201:21100/gzDigitalSignage"; let dev_url="http://36.33.26.201:21100/gzDigitalSignage";
let local_url="http://192.168.0.39:11998/gzDigitalSignage"; let local_url="http://192.168.0.38:11998/gzDigitalSignage";
let dataUrl = "http://112.27.246.86:21997/gzDigitalSignage" let dataUrl = "http://112.27.246.86:21997/gzDigitalSignage"
if(url.indexOf("36.33.26.201")!=-1){ if(url.indexOf("36.33.26.201")!=-1){
dataUrl = dev_url; dataUrl = dev_url;
}else if(url.indexOf("127.0.0.1")!=-1 || url.indexOf("localhost")!=-1 || url.indexOf("192.168.0.39")!=-1){ }else if(url.indexOf("127.0.0.1")!=-1 || url.indexOf("localhost")!=-1 || url.indexOf("192.168.0.38")!=-1){
dataUrl = local_url dataUrl = local_url
}else if(url.indexOf("192.168.0.14")!=-1){ }else if(url.indexOf("192.168.0.14")!=-1){
dataUrl = test_url dataUrl = test_url
@ -26,7 +26,7 @@ if(url.indexOf("36.33.26.201")!=-1){
// console.log(dataUrl) // console.log(dataUrl)
let imgUrl = dataUrl + '/files'; let imgUrl = dataUrl + '/files';
let tokens = localStorage.getItem("token"); let tokens = localStorage.getItem("gds-token");
function error(xhr) { function error(xhr) {
var msg = xhr.responseText; var msg = xhr.responseText;
@ -37,7 +37,7 @@ function error(xhr) {
if (code == 400) { if (code == 400) {
layer.msg(message); layer.msg(message);
} else if (code == 401 || status == 401) { } else if (code == 401 || status == 401) {
localStorage.removeItem("token"); localStorage.removeItem("gds-token");
localStorage.removeItem("user"); localStorage.removeItem("user");
localStorage.removeItem('pageType'); localStorage.removeItem('pageType');
top.layer.alert(message, { top.layer.alert(message, {
@ -60,7 +60,7 @@ function error(xhr) {
$.ajaxSetup({ $.ajaxSetup({
cache: false, cache: false,
headers: { headers: {
"Authorization": localStorage.getItem("token") "Authorization": localStorage.getItem("gds-token")
}, },
async: false, async: false,
error: function (xhr, textStatus, errorThrown) { error: function (xhr, textStatus, errorThrown) {

View File

@ -91,7 +91,7 @@
if (code == 400) { if (code == 400) {
layer.msg(message); layer.msg(message);
} else if (code == 401) { } else if (code == 401) {
localStorage.removeItem("token"); localStorage.removeItem("gds-token");
layer.msg("token过期请先登录", {shift: -1, time: 1000}, function(){ layer.msg("token过期请先登录", {shift: -1, time: 1000}, function(){
location.href = ctxPath + '/login.html'; location.href = ctxPath + '/login.html';
}); });

View File

@ -107,7 +107,7 @@ function init(){
if (code == 400) { if (code == 400) {
layer.msg(message); layer.msg(message);
} else if (code == 401) { } else if (code == 401) {
localStorage.removeItem("token"); localStorage.removeItem("gds-token")
layer.msg("token过期请先登录", {shift: -1, time: 1000}, function(){ layer.msg("token过期请先登录", {shift: -1, time: 1000}, function(){
location.href = '/login.html'; location.href = '/login.html';
}); });