Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
scrtsdk
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
胡懿
scrtsdk
Commits
1c573158
Commit
1c573158
authored
Apr 14, 2025
by
杨子
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
登录功能
parent
c4d8de4b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
68 additions
and
3 deletions
+68
-3
callbackUrl
callbackUrl
+2
-2
scrtLogin.html
src/main/resources/templates/scrtLogin.html
+66
-1
No files found.
callbackUrl
View file @
1c573158
url="http://localhost:8080/loginScrt"
url="http://localhost:8080/loginScrt"
securityServerUrl="127.0.0.1"
securityServerUrl="http://192.168.19.189:48080"
\ No newline at end of file
\ No newline at end of file
src/main/resources/templates/scrtLogin.html
View file @
1c573158
...
@@ -3,12 +3,76 @@
...
@@ -3,12 +3,76 @@
<head>
<head>
<meta
charset=
"UTF-8"
>
<meta
charset=
"UTF-8"
>
<title>
Title
</title>
<title>
Title
</title>
<style>
body
{
/** 页面居中 */
border-radius
:
20px
;
height
:
350px
;
position
:
absolute
;
left
:
50%
;
top
:
50%
;
transform
:
translate
(
-50%
,
-50%
);
}
</style>
<script
src=
"https://lf9-cdn-tos.bytecdntp.com/cdn/expire-1-M/jquery/2.1.2/jquery.min.js"
type=
"application/javascript"
></script>
</head>
</head>
<body>
<body>
<div>
123123123123
</div>
<h1>
跳转地址:
<span
th:text=
"${jumpUrl}"
></span></h1>
<h1>
跳转地址:
<span
th:text=
"${jumpUrl}"
></span></h1>
<h1>
登录地址:
<span
th:text=
"${securityServerUrl}"
></span></h1>
<h1>
登录地址:
<span
th:text=
"${securityServerUrl}"
></span></h1>
账号:
<input
id=
"username"
value=
"admin"
/>
<br
/>
密码:
<input
id=
"password"
value=
"admin123"
>
<br
/>
<button
style=
"float: right; margin-top: 5px;"
onclick=
"login()"
>
登录
</button>
<script
type=
"application/javascript"
>
// 获取登录地址
const
securityServerUrlElement
=
document
.
querySelector
(
'h1:nth-of-type(2) span'
);
const
securityServerUrl
=
securityServerUrlElement
?
securityServerUrlElement
.
textContent
:
''
;
console
.
log
(
'登录地址: '
,
securityServerUrl
);
// 获取跳转地址
const
jumpUrlElement
=
document
.
querySelector
(
'h1:nth-of-type(1) span'
);
const
jumpUrl
=
jumpUrlElement
?
jumpUrlElement
.
textContent
:
''
;
console
.
log
(
'跳转地址: '
,
jumpUrl
);
/**
* 账号密码登录
*/
function
login
()
{
const
clientId
=
'yudao-sso-demo-by-password'
;
// 可以改写成,你的 clientId
const
clientSecret
=
'test'
;
// 可以改写成,你的 clientSecret
const
grantType
=
'password'
;
// 密码模式
// 账号 + 密码
const
username
=
$
(
'#username'
).
val
();
const
password
=
$
(
'#password'
).
val
();
if
(
username
.
length
===
0
||
password
.
length
===
0
)
{
alert
(
'账号或密码未输入'
);
return
;
}
// 发起请求
$
.
ajax
({
url
:
securityServerUrl
+
"/admin-api/system/auth/loginScrt"
,
data
:
JSON
.
stringify
({
username
:
username
,
password
:
password
}),
method
:
'POST'
,
headers
:
{
'tenant-id'
:
'1'
,
// 多租户编号,写死
'Content-Type'
:
'application/json'
},
success
:
function
(
result
)
{
if
(
result
.
code
!==
0
)
{
alert
(
'登录失败,原因:'
+
result
.
msg
)
return
;
}
// 设置到 localStorage 中
localStorage
.
setItem
(
'ACCESS-TOKEN'
,
result
.
data
.
accessToken
);
localStorage
.
setItem
(
'REFRESH-TOKEN'
,
result
.
data
.
refreshToken
);
window
.
location
.
href
=
jumpUrl
+
'?token='
+
result
.
data
.
accessToken
+
'&refreshToken='
+
result
.
data
.
refreshToken
;
}
});
}
</script>
</body>
</body>
</html>
</html>
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment