106 lines
4.6 KiB
Plaintext
Raw Normal View History

2024-07-05 17:11:08 +08:00
<!DOCTYPE html>
<html>
<head>
<#import "./common/common.macro.ftl" as netCommon>
<@netCommon.commonStyle />
2024-07-05 17:11:08 +08:00
<link rel="stylesheet" href="${request.contextPath}/static/adminlte/plugins/iCheck/square/blue.css">
<title>${I18n.admin_name}</title>
2024-07-05 17:11:08 +08:00
</head>
<body class="hold-transition login-page">
<#-- <div class="login-box">-->
<#-- <div class="login-logo">-->
<#-- <a><b>XXL</b>JOB</a>-->
<#-- </div>-->
<#-- <form id="loginForm" method="post" >-->
<#-- <div class="login-box-body">-->
<#-- <p class="login-box-msg">${I18n.admin_name}</p>-->
<#-- <div class="form-group has-feedback">-->
<#-- <input type="text" name="userName" class="form-control" placeholder="${I18n.login_username_placeholder}" maxlength="18" >-->
<#-- <span class="glyphicon glyphicon-envelope form-control-feedback"></span>-->
<#-- </div>-->
<#-- <div class="form-group has-feedback">-->
<#-- <input type="password" name="password" class="form-control" placeholder="${I18n.login_password_placeholder}" maxlength="18" >-->
<#-- <span class="glyphicon glyphicon-lock form-control-feedback"></span>-->
<#-- </div>-->
<#-- <div class="row">-->
<#-- <div class="col-xs-8">-->
<#-- <div class="checkbox icheck">-->
<#-- <label>-->
<#-- <input type="checkbox" name="ifRemember" > &nbsp; ${I18n.login_remember_me}-->
<#-- </label>-->
<#-- </div>-->
<#-- </div><!-- /.col &ndash;&gt;-->
<#-- <div class="col-xs-4">-->
<#-- <button type="submit" class="btn btn-primary btn-block btn-flat">${I18n.login_btn}</button>-->
<#-- </div>-->
<#-- </div>-->
<#-- </div>-->
<#-- </form>-->
<#-- </div>-->
2024-07-05 17:11:08 +08:00
<@netCommon.commonScript />
<#--<script src="${request.contextPath}/static/adminlte/plugins/iCheck/icheck.min.js"></script>-->
<#--<script src="${request.contextPath}/static/js/login.1.js"></script>-->
<script src="${request.contextPath}/static/adminlte/bower_components/jquery/jquery.min.js"></script>
<script>
/**
* 跳转单点登录
*/
function ssoLogin() {
const clientId = 'ludu-job-admin'; // 可以改写成,你的 clientId
const redirectUri = encodeURIComponent('http://127.0.0.1:9090/xxl-job-admin/toLogin'); // 注意,需要使用 encodeURIComponent 编码地址
const responseType = 'code'; // 1授权码模式对应 code2简化模式对应 token
window.location.href = 'http://127.0.0.1:80/sso?client_id=' + clientId
+ '&redirect_uri=' + redirectUri
+ '&response_type=' + responseType;
}
const accessToken = localStorage.getItem('ACCESS-TOKEN');
// 情况一:未登录
if (!accessToken) {
// 获取 URL 中的查询参数
let urlParams = new URLSearchParams(window.location.search);
// 获取 code 参数的值
let code = urlParams.get('code');
if (!code) {
ssoLogin();
} else {
// 提交
const redirectUri = 'http://127.0.0.1:9090/xxl-job-admin/toLogin'; // 需要修改成,你回调的地址,就是在 index.html 拼接的 redirectUri
$.ajax({
url: "http://127.0.0.1:9090/xxl-job-admin/auth/login-by-code?code=" + code
+ '&redirectUri=' + redirectUri,
method: 'POST',
success: function( result ) {
if (result.code !== 0) {
// layer.open({
// title: I18n.system_tips,
// btn: [ I18n.system_ok ],
// content: (data.msg || (I18n.jobgroup_del + I18n.system_fail)),
// icon: '2'
// });
alert('获得访问令牌失败,原因:' + result.msg)
return;
}
// 设置到 localStorage 中
localStorage.setItem('ACCESS-TOKEN', result.data.access_token);
localStorage.setItem('REFRESH-TOKEN', result.data.refresh_token);
localStorage.setItem('EXPIRES-IN', Date.now() + result.data.expires_in * 1000);
// 跳转回首页
window.location.href = '/xxl-job-admin';
}
})
}
}
// 情况二Token失效暂未实现
else if (Date.now() > localStorage.getItem('EXPIRES-IN')) {
console.log('重新获取授权码')
}
// 情况三:已登录
else {
window.location.href = '/xxl-job-admin';
}
</script>
2024-07-05 17:11:08 +08:00
</body>
</html>