Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
hrs_app_h5
/
bill
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
7c72fb15
authored
May 01, 2020
by
张建朝
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
tj
parent
1610e61a
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
87 additions
and
9 deletions
src/router/index.js
src/store/index.js
src/views/OidcCallback.vue
src/router/index.js
View file @
7c72fb15
...
...
@@ -27,19 +27,84 @@ const router = new VueRouter({
return
{
x
:
0
,
y
:
0
}
}
})
//自动登录
function
autoLogin
(
payload
=
{
autoCode
,
redirectPath
}){
store
.
dispatch
(
"authenticateOidc"
,{
options
:{
extraQueryParams
:{
authcode
:
payload
.
autoCode
},
redirectPath
:
payload
.
redirectPath
}
});
}
//router.beforeEach(vuexOidcCreateRouterMiddleware(store));
const
loginStorage
=
localStorage
;
const
autoLoginParamsKey
=
"autoLoginParams"
;
function
setAutoLogin
(
payload
=
{
autoCode
,
redirectPath
}){
loginStorage
.
setItem
(
autoLoginParamsKey
,
JSON
.
stringify
(
payload
))
}
function
getAutoLoginParams
(){
const
paramStr
=
loginStorage
.
getItem
(
autoLoginParamsKey
);
if
(
!!
paramStr
){
loginStorage
.
removeItem
(
autoLoginParamsKey
);
return
JSON
.
parse
(
paramStr
);
}
return
null
;
}
router
.
beforeEach
((
to
,
from
,
next
)
=>
{
const
authcode
=
to
.
query
.
authcode
;
const
params
=
{
to
,
authcode
}
store
.
dispatch
(
'oidcCheckAccess'
,
params
).
then
(
function
(
hasAccess
)
{
if
(
hasAccess
)
{
//如果有登录参数则优先登录
router
.
beforeEach
((
to
,
from
,
next
)
=>
{
const
autoLoginParams
=
getAutoLoginParams
();
if
(
autoLoginParams
){
autoLogin
(
autoLoginParams
);
}
else
{
next
();
}
})
router
.
beforeEach
((
to
,
from
,
next
)
=>
{
const
authcode
=
to
.
query
.
authcode
;
if
(
!!
authcode
){
var
toPath
=
to
.
path
||
"/"
;
for
(
let
key
in
to
.
query
){
if
(
key
==
'authcode'
){
continue
;
}
toPath
+=
toPath
.
indexOf
(
"?"
)
>-
1
?
"&"
:
"?"
;
toPath
+=
`
${
key
}
=
${
to
.
query
}
`
;
}
const
userId
=
to
.
query
.
userid
||
to
.
query
.
userId
;
const
isAuth
=
store
.
getters
.
oidcIsAuthenticated
;
console
.
log
(
isAuth
)
// if(isAuth){
store
.
dispatch
(
"getOidcUser"
).
then
(
oidcUser
=>
{
if
(
oidcUser
){
//如果登录用户与当前登录用户不匹配,则保存登录参数,退出
if
(
oidcUser
.
profile
.
sub
!=
userId
){
setAutoLogin
({
autoCode
:
authcode
,
redirectPath
:
toPath
})
store
.
dispatch
(
"signOutOidc"
)
}
else
{
next
()
}
}
else
{
autoLogin
({
autoCode
:
authcode
,
redirectPath
:
toPath
})
}
}).
catch
(()
=>
{
autoLogin
({
autoCode
:
authcode
,
redirectPath
:
toPath
})
});
}
else
{
next
()
}
})
router
.
beforeEach
(
vuexOidcCreateRouterMiddleware
(
store
));
//TODO: 把callBack中的app_register_id逻辑替换到这里
export
default
router
src/store/index.js
View file @
7c72fb15
...
...
@@ -5,7 +5,8 @@ import oidcSettings from "../utils/oidcSettings";
import
bill
from
'./modules/bill'
import
token
from
'./modules/token'
import
any
from
'./modules/any'
import
more
from
'./modules/more'
import
more
from
'./modules/more'
;
import
api
from
'../api/index'
Vue
.
use
(
Vuex
)
...
...
@@ -15,6 +16,14 @@ export default new Vuex.Store({
token
,
any
,
more
,
oidc
:
vuexOidcCreateStoreModule
(
oidcSettings
)
oidc
:
vuexOidcCreateStoreModule
(
oidcSettings
,
{
isAuthenticatedBy
:
'access_token'
,
dispatchEventsOnWindow
:
true
},{
userLoaded
:(
user
)
=>
{
console
.
log
(
"userLoaded=>"
,
user
)
}
})
}
});
src/views/OidcCallback.vue
View file @
7c72fb15
...
...
@@ -18,6 +18,9 @@ export default {
methods
:
{
...
mapActions
([
"oidcSignInCallback"
,
"getOidcUser"
]),
getQueryString
(
urlsearch
,
name
)
{
if
(
!
urlsearch
){
return
null
;
}
var
reg
=
new
RegExp
(
"(^|&)"
+
name
+
"=([^&]*)(&|$)"
);
var
r
=
urlsearch
.
match
(
reg
);
if
(
r
!=
null
)
return
unescape
(
r
[
2
]);
...
...
@@ -60,9 +63,10 @@ export default {
mounted
()
{
this
.
oidcSignInCallback
()
.
then
(
redirectPath
=>
{
console
.
log
(
2
);
console
.
log
(
2
,
redirectPath
);
this
.
getOidcUser
()
.
then
(
user
=>
{
let
urlsearch
=
redirectPath
.
split
(
"?"
)[
1
];
let
appid
=
this
.
getQueryString
(
urlsearch
,
"appid"
);
this
.
getToken
(
user
.
access_token
,
appid
,
redirectPath
);
...
...
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