Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
dinky
Project
Project
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
wangpeng
dinky
Commits
1ef32561
Unverified
Commit
1ef32561
authored
Jul 25, 2023
by
zhu-mingye
Committed by
GitHub
Jul 25, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Feature] added user token info (#2149)
parent
0a332896
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
134 additions
and
16 deletions
+134
-16
AdminController.java
...n/src/main/java/org/dinky/controller/AdminController.java
+12
-0
UserDTO.java
dinky-admin/src/main/java/org/dinky/data/dto/UserDTO.java
+2
-0
UserServiceImpl.java
...src/main/java/org/dinky/service/impl/UserServiceImpl.java
+1
-0
app.tsx
dinky-web/src/app.tsx
+1
-0
index.tsx
...b/src/pages/DataStudio/MiddleContainer/KeyBoard/index.tsx
+4
-1
constant.tsx
.../pages/DataStudio/MiddleContainer/QuickGuide/constant.tsx
+47
-5
index.tsx
...src/pages/DataStudio/MiddleContainer/QuickGuide/index.tsx
+10
-7
function.tsx
dinky-web/src/pages/Other/Login/function.tsx
+8
-0
index.tsx
dinky-web/src/pages/Other/Login/index.tsx
+31
-3
constants.tsx
dinky-web/src/services/constants.tsx
+1
-0
data.d.ts
dinky-web/src/services/data.d.ts
+4
-0
data.d.ts
dinky-web/src/types/User/data.d.ts
+13
-0
No files found.
dinky-admin/src/main/java/org/dinky/controller/AdminController.java
View file @
1ef32561
...
@@ -35,6 +35,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
...
@@ -35,6 +35,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.RestController
;
import
cn.dev33.satoken.stp.SaTokenInfo
;
import
cn.dev33.satoken.stp.StpUtil
;
import
lombok.RequiredArgsConstructor
;
import
lombok.RequiredArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
...
@@ -93,4 +95,14 @@ public class AdminController {
...
@@ -93,4 +95,14 @@ public class AdminController {
public
Result
<
Tenant
>
switchingTenant
(
@RequestParam
(
"tenantId"
)
Integer
tenantId
)
{
public
Result
<
Tenant
>
switchingTenant
(
@RequestParam
(
"tenantId"
)
Integer
tenantId
)
{
return
userService
.
chooseTenant
(
tenantId
);
return
userService
.
chooseTenant
(
tenantId
);
}
}
/**
* get tenant info
*
* @return {@link Result}{@link SaTokenInfo}
*/
@GetMapping
(
"/tokenInfo"
)
public
Result
<
SaTokenInfo
>
getTokenInfo
()
{
return
Result
.
succeed
(
StpUtil
.
getTokenInfo
());
}
}
}
dinky-admin/src/main/java/org/dinky/data/dto/UserDTO.java
View file @
1ef32561
...
@@ -25,6 +25,7 @@ import org.dinky.data.model.User;
...
@@ -25,6 +25,7 @@ import org.dinky.data.model.User;
import
java.util.List
;
import
java.util.List
;
import
cn.dev33.satoken.stp.SaTokenInfo
;
import
lombok.AllArgsConstructor
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
lombok.NoArgsConstructor
;
...
@@ -38,4 +39,5 @@ public class UserDTO {
...
@@ -38,4 +39,5 @@ public class UserDTO {
private
List
<
Role
>
roleList
;
private
List
<
Role
>
roleList
;
private
List
<
Tenant
>
tenantList
;
private
List
<
Tenant
>
tenantList
;
private
Tenant
currentTenant
;
private
Tenant
currentTenant
;
private
SaTokenInfo
tokenInfo
;
}
}
dinky-admin/src/main/java/org/dinky/service/impl/UserServiceImpl.java
View file @
1ef32561
...
@@ -427,6 +427,7 @@ public class UserServiceImpl extends SuperServiceImpl<UserMapper, User> implemen
...
@@ -427,6 +427,7 @@ public class UserServiceImpl extends SuperServiceImpl<UserMapper, User> implemen
userInfo
.
setUser
(
user
);
userInfo
.
setUser
(
user
);
userInfo
.
setRoleList
(
roleList
);
userInfo
.
setRoleList
(
roleList
);
userInfo
.
setTenantList
(
tenantList
);
userInfo
.
setTenantList
(
tenantList
);
userInfo
.
setTokenInfo
(
StpUtil
.
getTokenInfo
());
return
userInfo
;
return
userInfo
;
}
}
}
}
dinky-web/src/app.tsx
View file @
1ef32561
...
@@ -65,6 +65,7 @@ export async function getInitialState(): Promise<{
...
@@ -65,6 +65,7 @@ export async function getInitialState(): Promise<{
roleList
:
result
.
datas
.
roleList
,
roleList
:
result
.
datas
.
roleList
,
tenantList
:
result
.
datas
.
tenantList
,
tenantList
:
result
.
datas
.
tenantList
,
currentTenant
:
result
.
datas
.
currentTenant
,
currentTenant
:
result
.
datas
.
currentTenant
,
tokenInfo
:
result
.
datas
.
saTokenInfo
,
};
};
return
currentUser
;
return
currentUser
;
},
(
error
)
=>
{
},
(
error
)
=>
{
...
...
dinky-web/src/pages/DataStudio/MiddleContainer/KeyBoard/index.tsx
View file @
1ef32561
...
@@ -31,7 +31,10 @@ const KeyBoard = () => {
...
@@ -31,7 +31,10 @@ const KeyBoard = () => {
const
buildKeyBoard
=
()
=>
{
const
buildKeyBoard
=
()
=>
{
return
KEY_BOARD
.
map
((
item
,
index
)
=>
{
return
KEY_BOARD
.
map
((
item
,
index
)
=>
{
return
<>
return
<>
{
index
%
6
===
0
?
<
Divider
plain
orientationMargin=
{
0
}
/>
:
<>
{
index
%
6
===
0
?
<>
<
Divider
plain
orientationMargin=
{
0
}
/>
<
Text
keyboard
>
{
item
.
label
}
</
Text
>
{
item
.
description
}
<
Divider
type=
"vertical"
/>
</>:
<>
<
Text
keyboard
>
{
item
.
label
}
</
Text
>
{
item
.
description
}
<
Divider
type=
"vertical"
/>
<
Text
keyboard
>
{
item
.
label
}
</
Text
>
{
item
.
description
}
<
Divider
type=
"vertical"
/>
</>
}
</>
}
</>
</>
...
...
dinky-web/src/pages/DataStudio/MiddleContainer/QuickGuide/constant.tsx
View file @
1ef32561
...
@@ -20,12 +20,53 @@
...
@@ -20,12 +20,53 @@
export
const
QUICK_GUIDE
=
[
export
const
QUICK_GUIDE
=
[
{
{
key
:
'registcluster'
,
key
:
'clusterInstance'
,
label
:
'注册 Session 集群'
,
link
:
'/registration/cluster/instance'
},{
key
:
'registcluster'
,
label
:
'注册 Session 集群'
,
label
:
'注册 Session 集群'
,
link
:
'/registration/cluster/instance'
link
:
'/registration/cluster/instance'
},
{
key
:
'clusterConfiguration'
,
label
:
'注册集群配置'
,
link
:
'/registration/cluster/configuration'
},
{
key
:
'database'
,
label
:
'注册数据源'
,
link
:
'/registration/database'
},
{
key
:
'alertInstance'
,
label
:
'注册告警实例'
,
link
:
'/registration/alert/instance'
},
{
key
:
'alertGroup'
,
label
:
'注册告警组'
,
link
:
'/registration/alert/group'
},
{
key
:
'fragment'
,
label
:
'全局变量'
,
link
:
'/registration/fragment'
},
{
key
:
'document'
,
label
:
'文档'
,
link
:
'/registration/document'
},
{
key
:
'gitprojects'
,
label
:
'Git 项目'
,
link
:
'/registration/gitprojects'
},
{
key
:
'udf'
,
label
:
'UDF'
,
link
:
'/registration/udf'
},
{
key
:
'resource'
,
label
:
'资源'
,
link
:
'/registration/resource'
}
}
];
];
\ No newline at end of file
dinky-web/src/pages/DataStudio/MiddleContainer/QuickGuide/index.tsx
View file @
1ef32561
...
@@ -20,8 +20,9 @@
...
@@ -20,8 +20,9 @@
import
{
Divider
,
Typography
}
from
"antd"
;
import
{
Divider
,
Typography
}
from
"antd"
;
import
React
from
"react"
;
import
React
from
"react"
;
import
{
QUICK_GUIDE
}
from
"@/pages/DataStudio/MiddleContainer/QuickGuide/constant"
;
import
{
QUICK_GUIDE
}
from
"@/pages/DataStudio/MiddleContainer/QuickGuide/constant"
;
import
{
Link
}
from
"@umijs/max"
;
const
{
Title
,
Paragraph
,
Link
}
=
Typography
;
const
{
Title
,
Paragraph
}
=
Typography
;
...
@@ -30,9 +31,12 @@ const QuickGuide = () => {
...
@@ -30,9 +31,12 @@ const QuickGuide = () => {
const
buildQuickGuide
=
()
=>
{
const
buildQuickGuide
=
()
=>
{
return
QUICK_GUIDE
.
map
((
item
,
index
)
=>
{
return
QUICK_GUIDE
.
map
((
item
,
index
)
=>
{
return
<>
return
<>
{
index
%
7
===
0
?
<
Divider
plain
orientationMargin=
{
0
}
/>
:
<>
{
index
%
10
===
0
?
<>
<
Link
href=
{
item
.
link
}
key=
{
item
.
key
}
>
{
item
.
label
}
</
Link
>
<
Divider
plain
orientationMargin=
{
0
}
/>
<
Link
to=
{
item
.
link
}
key=
{
item
.
key
}
>
{
item
.
label
}
</
Link
>
</>
:
<>
<
Divider
type=
"vertical"
/>
<
Divider
type=
"vertical"
/>
<
Link
to=
{
item
.
link
}
key=
{
item
.
key
}
>
{
item
.
label
}
</
Link
>
</>
}
</>
}
</>
</>
});
});
...
@@ -41,10 +45,9 @@ const QuickGuide = () => {
...
@@ -41,10 +45,9 @@ const QuickGuide = () => {
return
<>
return
<>
<
Typography
style=
{
{
padding
:
'2px'
,
textAlign
:
'center'
,
border
:
'salmon'
}
}
>
<
Typography
style=
{
{
padding
:
'2px'
,
textAlign
:
'center'
,
border
:
'salmon'
}
}
>
<
Title
level=
{
4
}
>
快捷引导
</
Title
>
<
Title
level=
{
4
}
>
快捷引导
</
Title
>
todo: buildQuickGuide
<
Paragraph
style=
{
{
padding
:
0
,
margin
:
0
,
textAlign
:
'center'
,
border
:
'salmon'
}
}
>
{
/*<Paragraph style={{padding: 0, margin: 0, textAlign: 'center', border: 'salmon'}} >*/
}
{
buildQuickGuide
()
}
{
/* {buildQuickGuide()}*/
}
</
Paragraph
>
{
/*</Paragraph>*/
}
</
Typography
>
</
Typography
>
</>
</>
};
};
...
...
dinky-web/src/pages/Other/Login/function.ts
→
dinky-web/src/pages/Other/Login/function.ts
x
View file @
1ef32561
...
@@ -20,6 +20,7 @@
...
@@ -20,6 +20,7 @@
import
{
history
}
from
"@@/core/history"
;
import
{
history
}
from
"@@/core/history"
;
/** 此方法会跳转到 redirect 参数所在的位置 */
/** 此方法会跳转到 redirect 参数所在的位置 */
export
const
gotoRedirectUrl
=
()
=>
{
export
const
gotoRedirectUrl
=
()
=>
{
if
(
!
history
)
return
;
if
(
!
history
)
return
;
...
@@ -28,3 +29,9 @@ export const gotoRedirectUrl = () => {
...
@@ -28,3 +29,9 @@ export const gotoRedirectUrl = () => {
history
.
push
(
urlParams
.
get
(
"redirect"
)
||
"/"
);
history
.
push
(
urlParams
.
get
(
"redirect"
)
||
"/"
);
},
10
);
},
10
);
};
};
export
const
redirectToLogin
=
()
=>
{
//TODO: 弹出确认框
window
.
location
.
href
=
'/login'
};
\ No newline at end of file
dinky-web/src/pages/Other/Login/index.tsx
View file @
1ef32561
...
@@ -20,9 +20,9 @@ import {setTenantStorageAndCookie} from "@/utils/function";
...
@@ -20,9 +20,9 @@ import {setTenantStorageAndCookie} from "@/utils/function";
import
{
l
}
from
"@/utils/intl"
;
import
{
l
}
from
"@/utils/intl"
;
import
{
useEmotionCss
}
from
"@ant-design/use-emotion-css"
;
import
{
useEmotionCss
}
from
"@ant-design/use-emotion-css"
;
import
{
useModel
}
from
"@umijs/max"
;
import
{
useModel
}
from
"@umijs/max"
;
import
React
,
{
useState
}
from
"react"
;
import
React
,
{
use
Effect
,
use
State
}
from
"react"
;
import
{
flushSync
}
from
"react-dom"
;
import
{
flushSync
}
from
"react-dom"
;
import
{
chooseTenantSubmit
,
login
}
from
"@/services/BusinessCrud"
;
import
{
chooseTenantSubmit
,
login
,
queryDataByParams
}
from
"@/services/BusinessCrud"
;
import
{
import
{
ErrorMessage
,
ErrorMessage
,
SuccessMessageAsync
,
SuccessMessageAsync
,
...
@@ -31,8 +31,10 @@ import {UserBaseInfo} from "@/types/User/data";
...
@@ -31,8 +31,10 @@ import {UserBaseInfo} from "@/types/User/data";
import
LoginForm
from
"./LoginForm"
;
import
LoginForm
from
"./LoginForm"
;
import
HelmetTitle
from
"./HelmetTitle"
;
import
HelmetTitle
from
"./HelmetTitle"
;
import
ChooseModal
from
"@/pages/Other/Login/ChooseModal"
;
import
ChooseModal
from
"@/pages/Other/Login/ChooseModal"
;
import
{
gotoRedirectUrl
}
from
"@/pages/Other/Login/function"
;
import
{
gotoRedirectUrl
,
redirectToLogin
}
from
"@/pages/Other/Login/function"
;
import
LangSwitch
from
"@/pages/Other/Login/LangSwitch"
;
import
LangSwitch
from
"@/pages/Other/Login/LangSwitch"
;
import
{
useLocalStorage
}
from
"@/utils/hook/useLocalStorage"
;
import
{
API_CONSTANTS
}
from
"@/services/constants"
;
const
Login
:
React
.
FC
=
()
=>
{
const
Login
:
React
.
FC
=
()
=>
{
const
[
submitting
,
setSubmitting
]
=
useState
(
false
);
const
[
submitting
,
setSubmitting
]
=
useState
(
false
);
...
@@ -40,6 +42,8 @@ const Login: React.FC = () => {
...
@@ -40,6 +42,8 @@ const Login: React.FC = () => {
const
[
tenantVisible
,
handleTenantVisible
]
=
useState
<
boolean
>
(
false
);
const
[
tenantVisible
,
handleTenantVisible
]
=
useState
<
boolean
>
(
false
);
const
[
tenant
,
setTenant
]
=
useState
<
UserBaseInfo
.
Tenant
[]
>
([]);
const
[
tenant
,
setTenant
]
=
useState
<
UserBaseInfo
.
Tenant
[]
>
([]);
const
[
localStorageOfToken
,
setLocalStorageOfToken
]
=
useLocalStorage
(
"token"
,
""
);
const
containerClassName
=
useEmotionCss
(()
=>
{
const
containerClassName
=
useEmotionCss
(()
=>
{
return
{
return
{
display
:
"flex"
,
display
:
"flex"
,
...
@@ -60,6 +64,26 @@ const Login: React.FC = () => {
...
@@ -60,6 +64,26 @@ const Login: React.FC = () => {
}
}
};
};
/**
* When the token is expired, redirect to login
*/
useEffect
(()
=>
{
const
expirationTime
=
JSON
.
parse
(
JSON
.
stringify
(
localStorageOfToken
)).
tokenTimeout
??
0
;
// GET TOKEN TIMEOUT
let
timeRemaining
=
0
;
let
timer
:
NodeJS
.
Timeout
;
if
(
expirationTime
>
0
)
{
// calculate the time difference
const
currentTime
=
Date
.
now
();
timeRemaining
=
expirationTime
-
currentTime
;
// use setInterval to set a timer
timer
=
setInterval
(()
=>
redirectToLogin
(),
timeRemaining
);
}
return
()
=>
{
clearTimeout
(
timer
);
}
},[
initialState
,
localStorageOfToken
])
const
handleChooseTenant
=
async
(
chooseTenantResult
:
API
.
Result
)
=>
{
const
handleChooseTenant
=
async
(
chooseTenantResult
:
API
.
Result
)
=>
{
if
(
chooseTenantResult
.
code
===
0
)
{
if
(
chooseTenantResult
.
code
===
0
)
{
await
SuccessMessageAsync
(
l
(
"login.chooseTenantSuccess"
,
""
,
{
await
SuccessMessageAsync
(
l
(
"login.chooseTenantSuccess"
,
""
,
{
...
@@ -109,6 +133,10 @@ const Login: React.FC = () => {
...
@@ -109,6 +133,10 @@ const Login: React.FC = () => {
try
{
try
{
// login
// login
const
result
=
await
login
({...
values
});
const
result
=
await
login
({...
values
});
if
(
result
.
code
===
0
){
// if login success then get token info and set it to local storage
await
queryDataByParams
(
API_CONSTANTS
.
TOKEN_INFO
).
then
(
res
=>
setLocalStorageOfToken
(
JSON
.
stringify
(
res
)));
}
setInitialState
((
s
)
=>
({...
s
,
currentUser
:
result
.
datas
}));
setInitialState
((
s
)
=>
({...
s
,
currentUser
:
result
.
datas
}));
await
SuccessMessageAsync
(
l
(
"login.result"
,
""
,
{
msg
:
result
.
msg
,
time
:
result
.
time
}));
await
SuccessMessageAsync
(
l
(
"login.result"
,
""
,
{
msg
:
result
.
msg
,
time
:
result
.
time
}));
/**
/**
...
...
dinky-web/src/services/constants.tsx
View file @
1ef32561
...
@@ -26,6 +26,7 @@ export const API_CONSTANTS = {
...
@@ -26,6 +26,7 @@ export const API_CONSTANTS = {
// --- user ---
// --- user ---
// login path
// login path
LOGIN_PATH
:
"/user/login"
,
LOGIN_PATH
:
"/user/login"
,
TOKEN_INFO
:
"/api/tokenInfo"
,
// user login
// user login
LOGIN
:
"/api/login"
,
LOGIN
:
"/api/login"
,
// current user info
// current user info
...
...
dinky-web/src/services/data.d.ts
View file @
1ef32561
...
@@ -15,6 +15,9 @@
...
@@ -15,6 +15,9 @@
* limitations under the License.
* limitations under the License.
*/
*/
import
{
SaTokenInfo
}
from
"@/types/User/data"
;
declare
namespace
API
{
declare
namespace
API
{
type
Result
=
{
type
Result
=
{
code
:
number
;
code
:
number
;
...
@@ -28,6 +31,7 @@ declare namespace API {
...
@@ -28,6 +31,7 @@ declare namespace API {
roleList
?:
UserBaseInfo
.
Role
[];
roleList
?:
UserBaseInfo
.
Role
[];
tenantList
?:
UserBaseInfo
.
Tenant
[];
tenantList
?:
UserBaseInfo
.
Tenant
[];
currentTenant
?:
UserBaseInfo
.
Tenant
;
currentTenant
?:
UserBaseInfo
.
Tenant
;
tokenInfo
:
SaTokenInfo
;
};
};
type
PageParams
=
{
type
PageParams
=
{
...
...
dinky-web/src/types/User/data.d.ts
View file @
1ef32561
...
@@ -55,6 +55,19 @@ declare namespace UserBaseInfo {
...
@@ -55,6 +55,19 @@ declare namespace UserBaseInfo {
};
};
}
}
export
type
SaTokenInfo
=
{
tokenName
:
string
;
tokenValue
:
string
;
isLogin
:
boolean
;
loginId
:
number
;
loginType
:
string
;
tokenTimeout
:
number
;
sessionTimeout
:
number
;
tokenSessionTimeout
:
number
;
tokenActivityTimeout
:
number
;
loginDevice
:
string
;
tag
:
string
;
}
export
type
RowPermissions
=
ExcludeNameAndEnableColumns
&
{
export
type
RowPermissions
=
ExcludeNameAndEnableColumns
&
{
...
...
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