Browse Source

AUTH CROSS

release_0.0.2
yuan_yi 3 years ago
parent
commit
63e8968c10
  1. 1
      code/VideoAccess-VCMP/api/.vscode/launch.json
  2. 1
      code/VideoAccess-VCMP/api/app/lib/controllers/camera/create.js
  3. 18
      code/VideoAccess-VCMP/api/app/lib/controllers/nvr/index.js
  4. 7
      code/VideoAccess-VCMP/api/app/lib/service/paasRequest.js
  5. 8
      code/VideoAccess-VCMP/api/config.js
  6. 6
      code/VideoAccess-VCMP/web/client/src/layout/components/header/index.jsx
  7. 22
      code/VideoAccess-VCMP/web/client/src/layout/containers/layout/index.jsx
  8. 23
      code/VideoAccess-VCMP/web/client/src/layout/index.jsx
  9. 13
      code/VideoAccess-VCMP/web/client/src/sections/auth/actions/auth.js
  10. 12
      code/VideoAccess-VCMP/web/client/src/sections/auth/containers/login.jsx

1
code/VideoAccess-VCMP/api/.vscode/launch.json

@ -20,6 +20,7 @@
"--redisPort 6379",
"--axyApiUrl http://127.0.0.1:4100",
"--iotAuthApi http://127.0.0.1:4200",
"--iotVideoServerUrl http://221.230.55.27:8081",
"--godUrl https://restapi.amap.com/v3",
"--godKey 21c2d970e1646bb9a795900dd00093ce"
]

1
code/VideoAccess-VCMP/api/app/lib/controllers/camera/create.js

@ -161,6 +161,7 @@ async function createNvrCamera (ctx) {
})
} else {
createData.push({
type: 'nvr',
serialNo: c.streamid,
name: c.name,
sip: corCamera.sipip,

18
code/VideoAccess-VCMP/api/app/lib/controllers/nvr/index.js

@ -243,7 +243,20 @@ async function detail (ctx) {
}
const corUser = await ctx.app.fs.authRequest.get(`user/${nvrRes.createUserId}/message`, { query: { token } })
const serverDRes = (await ctx.app.fs.videoServerRequest.post(`gateway/plugins`) || '')
const serverDArr = JSON.parse(serverDRes.replace(/'/g, '"')) || []
const serverDConfig = serverDArr.find(s => s.Name == 'GB28181')
let serveD = {}
if (serverDConfig) {
const { Config } = serverDConfig
let ConfigArr = Config.split('\n')
for (let c of ConfigArr) {
let config = c.split(' = ')
if (config.length == 2) {
serveD[config[0].trim()] = config[1].trim().replace(/\"/g, '')
}
}
}
let nvrDetail = {
...nvrRes.dataValues,
station: bindStations,
@ -251,7 +264,8 @@ async function detail (ctx) {
createUser: {
namePresent: corUser[0].namePresent
},
accessWay: 'GB/T28181'
accessWay: 'GB/T28181',
accessInfo: serveD
}
ctx.status = 200;

7
code/VideoAccess-VCMP/api/app/lib/service/paasRequest.js

@ -2,9 +2,10 @@
const request = require('superagent')
class paasRequest {
constructor(root, { query = {} } = {}) {
constructor(root, { query = {} } = {}, option) {
this.root = root;
this.query = query
this.option = option
}
#buildUrl = (url) => {
@ -16,7 +17,7 @@ class paasRequest {
if (err) {
reject(err);
} else {
resolve(res.body);
resolve(res[this.option.dataWord]);
}
};
}
@ -51,7 +52,7 @@ function factory (app, opts) {
try {
for (let r of opts.pssaRequest) {
if (r.name && r.root) {
app.fs[r.name] = new paasRequest(r.root, { ...(r.params || {}) })
app.fs[r.name] = new paasRequest(r.root, { ...(r.params || {}) }, { dataWord: r.dataWord || 'body' })
} else {
throw 'opts.pssaRequest 参数错误!'
}

8
code/VideoAccess-VCMP/api/config.js

@ -14,8 +14,9 @@ args.option(['f', 'fileHost'], '文件中心本地化存储: WebApi 服务器地
args.option('redisHost', 'redisHost');
args.option('redisPort', 'redisPort');
args.option('redisPswd', 'redisPassword');
args.option('iotAuthApi', 'IOT 鉴权 api');
args.option('axyApiUrl', '安心云 api');
args.option('iotAuthApi', 'IOT 鉴权 api');
args.option('iotVideoServerUrl', '视频后端服务地址');
args.option('godUrl', '高德地图API请求地址');
args.option('godKey', '高德地图API key');
@ -29,6 +30,7 @@ const IOTA_REDIS_SERVER_PORT = process.env.IOTA_REDIS_SERVER_PORT || flags.redis
const IOTA_REDIS_SERVER_PWD = process.env.IOTA_REDIS_SERVER_PWD || flags.redisPswd || "";//redis 密码
const IOT_AUTH_API = process.env.IOT_AUTH_API || flags.iotAuthApi;
const IOT_VIDEO_SERVER_URL = process.env.IOT_VIDEO_SERVER_URL || flags.iotVideoServerUrl
const AXY_API_URL = process.env.AXY_API_URL || flags.axyApiUrl;
const GOD_URL = process.env.GOD_URL || flags.godUrl || 'https://restapi.amap.com/v3';
const GOD_KEY = process.env.GOD_KEY || flags.godKey;
@ -85,6 +87,10 @@ const product = {
key: GOD_KEY
}
}
}, {
name: 'videoServerRequest',
root: IOT_VIDEO_SERVER_URL + '/api',
dataWord: 'text'
},]
}
}

6
code/VideoAccess-VCMP/web/client/src/layout/components/header/index.jsx

@ -13,6 +13,8 @@ const Header = (props) => {
onClick={({ itemKey }) => {
if (itemKey == "logout") {
dispatch(actions.auth.logout(user));
const iotAuth = document.getElementById('iotAuth').contentWindow;
iotAuth.postMessage({ action: 'logout' }, '*');
if (socket) {
socket.disconnect();
}
@ -30,7 +32,7 @@ const Header = (props) => {
logo: (
<img
src="/assets/images/background/logo.png"
style={{ display: "inline-block", width: 280, height: 52}}
style={{ display: "inline-block", width: 280, height: 52 }}
/>
),
text: "",
@ -73,7 +75,7 @@ const Header = (props) => {
);
};
function mapStateToProps(state) {
function mapStateToProps (state) {
const { global, auth, webSocket } = state;
return {
actions: global.actions,

22
code/VideoAccess-VCMP/web/client/src/layout/containers/layout/index.jsx

@ -26,7 +26,7 @@ let scrollbar
const LayoutContainer = props => {
const {
dispatch, msg, user, copyright, children, sections, clientWidth, clientHeight,
location, match, routes, history
location, match, routes, history, authCrossLoading
} = props
const [collapsed, setCollapsed] = useState(false)
@ -40,8 +40,6 @@ const LayoutContainer = props => {
}
useEffect(() => {
scrollbar = new PerfectScrollbar('#page-content', { suppressScrollX: true });
window.addEventListener('resize', resize_);
return () => {
window.removeEventListener('resize', resize_);
@ -50,7 +48,7 @@ const LayoutContainer = props => {
useEffect(() => {
NProgress.done();
if (!user || !user.authorized) {
if ((!user || !user.authorized) && !authCrossLoading) {
history.push('/signin');
}
if (msg) {
@ -71,13 +69,27 @@ const LayoutContainer = props => {
}
const dom = document.getElementById('page-content');
if (dom) {
if (!scrollbar) {
scrollbar = new PerfectScrollbar('#page-content', { suppressScrollX: true });
} else {
scrollbar.update();
dom.scrollTop = 0;
}
}
})
return (
<Layout id="layout">
{
authCrossLoading ?
<div style={{
position: 'absolute', height: '100%', width: '100%',
display: 'flex', alignItems: 'center', placeContent: 'center',
}}>
载入中...
</div>
:
<>
<Layout.Header>
<Header
user={user}
@ -123,6 +135,8 @@ const LayoutContainer = props => {
</div>
</Layout.Content>
</Layout>
</>
}
</Layout >
)
}

23
code/VideoAccess-VCMP/web/client/src/layout/index.jsx

@ -24,6 +24,7 @@ const Root = props => {
const [outerRoutes, setOuterRoutes] = useState([])
const [combineRoutes, setCombineRoutes] = useState([])
const [innnerRoutes, setInnerRoutes] = useState([])
const [authCrossLoading, setAuthCrossLoading] = useState(true)
const flatRoutes = (routes) => {
const combineRoutes = [];
@ -148,9 +149,24 @@ const Root = props => {
component={route.component}
/>
)))
window.addEventListener('message', async function (e) { // message
const { data } = e
if (data && data.action) {
if (data.action == 'initUser') {
await store.dispatch(actions.auth.initAuth(e.data))
} else if (data.action == 'logout') {
await store.dispatch(actions.auth.logout())
}
}
setAuthCrossLoading(false)
});
}, [])
return (
<>
{
store ?
<ConfigProvider locale={zhCN}>
<Provider store={store}>
@ -160,6 +176,7 @@ const Root = props => {
<Layout
history={history}
routes={innnerRoutes}
authCrossLoading={authCrossLoading}
>
{combineRoutes}
</Layout>
@ -172,6 +189,12 @@ const Root = props => {
</Provider>
</ConfigProvider>
: ''
}
<iframe id="iotAuth" src="http://localhost:5200/cross" style={{ position: 'absolute', top: 0 }} frameBorder={0} >
<p>你的浏览器不支持 iframe</p>
</iframe>
</>
)
}

13
code/VideoAccess-VCMP/web/client/src/sections/auth/actions/auth.js

@ -3,8 +3,12 @@
import { ApiTable, AuthRequest } from '$utils'
export const INIT_AUTH = 'INIT_AUTH';
export function initAuth () {
const user = JSON.parse(sessionStorage.getItem('user')) || {};
export function initAuth (userData) {
const sessionUser = JSON.parse(sessionStorage.getItem('user'))
const user = userData || sessionUser || {};
if (user.authorized && !sessionUser) {
sessionStorage.setItem('user', JSON.stringify(user))
}
return {
type: INIT_AUTH,
payload: {
@ -58,11 +62,12 @@ export function login (username, password) {
}
export const LOGOUT = 'LOGOUT';
export function logout (user) {
sessionStorage.removeItem('user');
export function logout () {
const user = JSON.parse(sessionStorage.getItem('user'))
AuthRequest.put(ApiTable.logout, {
token: user.token
});
sessionStorage.removeItem('user');
return {
type: LOGOUT
};

12
code/VideoAccess-VCMP/web/client/src/sections/auth/containers/login.jsx

@ -20,16 +20,11 @@ const Login = props => {
useEffect(() => {
if (user && user.authorized) {
const receiver = document.getElementById('iotAuth').contentWindow;
// receiver.postMessage(user, "http://localhost:4200/cross");
receiver.postMessage('user', "*");
const iotAuth = document.getElementById('iotAuth').contentWindow;
iotAuth.postMessage({ action: 'login', user: user }, '*');
dispatch(push('/equipmentWarehouse/nvr'));
localStorage.setItem('vcmp_selected_sider', JSON.stringify(['nvr']))
localStorage.setItem('vcmp_open_sider', JSON.stringify(['equipmentWarehouse']))
}
}, [user])
@ -86,9 +81,6 @@ const Login = props => {
<Button htmlType='submit' block theme="solid" style={{ marginTop: 17, height: 40, backgroundColor: '#1859C1' }}>立即登录</Button>
</Form>
</div>
<iframe loading="lazy" id="iotAuth" src="http://localhost:5200/cross" frameBorder={0}>
<p>你的浏览器不支持 iframe</p>
</iframe>
</div>
);
}

Loading…
Cancel
Save