From 52e18de9acda0be85c6c8db729b53c833e44b83d Mon Sep 17 00:00:00 2001 From: Jay Date: Mon, 27 Mar 2017 18:11:27 +0800 Subject: [PATCH] add page chk login --- includes/language/zh.json | 3 +- public/js/admin_bundle.js | 127 ++++++++++++++++++++++++++++--- public/locales/zh.json | 1 + route/api/system.js | 7 ++ src/admin.js | 36 +++++---- src/components/MainMenu/index.js | 1 + src/routes.js | 2 + 7 files changed, 150 insertions(+), 27 deletions(-) diff --git a/includes/language/zh.json b/includes/language/zh.json index e9d9f60..eba0b00 100644 --- a/includes/language/zh.json +++ b/includes/language/zh.json @@ -65,5 +65,6 @@ "ERR8002": "資料更新失敗", "ERR8003": "資料刪除失敗", "ERR8100": "DB連線失敗", - "ERR9000": "操作權限不足" + "ERR9000": "操作權限不足", + "ERR9001": "登入Token無效" } \ No newline at end of file diff --git a/public/js/admin_bundle.js b/public/js/admin_bundle.js index c2c543b..943c36d 100644 --- a/public/js/admin_bundle.js +++ b/public/js/admin_bundle.js @@ -80128,6 +80128,10 @@ var _ActionLinkAdd = __webpack_require__(1080); var _ActionLinkAdd2 = _interopRequireDefault(_ActionLinkAdd); +var _IPCam = __webpack_require__(1127); + +var _IPCam2 = _interopRequireDefault(_IPCam); + function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var Routes = _react2.default.createElement( @@ -80144,7 +80148,8 @@ var Routes = _react2.default.createElement( _react2.default.createElement(_reactRouter.Route, { path: 'modbus', component: _Modbus2.default }), _react2.default.createElement(_reactRouter.Route, { path: 'link', component: _ActionLink2.default }), _react2.default.createElement(_reactRouter.Route, { path: 'addlink', component: _ActionLinkAdd2.default }), - _react2.default.createElement(_reactRouter.Route, { path: 'modbuscmd', component: _ModbusCmd2.default }) + _react2.default.createElement(_reactRouter.Route, { path: 'modbuscmd', component: _ModbusCmd2.default }), + _react2.default.createElement(_reactRouter.Route, { path: 'ipcam', component: _IPCam2.default }) ); exports.default = Routes; @@ -87352,6 +87357,9 @@ var MainMenu = function MainMenu(_ref) { _react2.default.createElement(_Item2.default, { toLink: '/admin/link', txt: i18n && 't' in i18n ? i18n.t('menu.item.link') : '', permission: permissions.link, onClick: function onClick() { return toggleMenu(); } }), + _react2.default.createElement(_Item2.default, { toLink: '/admin/ipcam', txt: i18n && 't' in i18n ? i18n.t('menu.item.ipcam') : '', permission: permissions.ipcam, onClick: function onClick() { + return toggleMenu(); + } }), _react2.default.createElement(_Item2.default, { toLink: '/admin', txt: i18n && 't' in i18n ? i18n.t('menu.item.logout') : '', permission: true, onClick: function onClick() { sessionStorage.clear(); location.replace('/'); @@ -91414,17 +91422,22 @@ var PageRoot = function (_React$Component) { _createClass(PageRoot, [{ key: 'componentDidMount', value: function componentDidMount() { - var lang = navigator.language.substring(0, 2); - fetch('/locales/' + lang + '.json').then(function (response) { - if (response.status == 200) return response.json(); - return {}; + fetch('/api/system/chklogin', (0, _actions.getRequest)()).then(function (response) { + return response.json(); }).then(function (json) { - var lang = Object.keys(json)[0] || ''; - _i18next2.default.init({ - lng: lang, - resources: json - }, function () { - store.dispatch((0, _actions.set_i18n)(_i18next2.default)); + if (json.status != 1) return location.replace('/'); + var lang = navigator.language.substring(0, 2); + fetch('/locales/' + lang + '.json').then(function (response) { + if (response.status == 200) return response.json(); + return {}; + }).then(function (json) { + var lang = Object.keys(json)[0] || ''; + _i18next2.default.init({ + lng: lang, + resources: json + }, function () { + store.dispatch((0, _actions.set_i18n)(_i18next2.default)); + }); }); }); } @@ -91444,5 +91457,97 @@ var PageRoot = function (_React$Component) { _reactDom2.default.render(_react2.default.createElement(PageRoot, null), document.getElementById('app')); +/***/ }), +/* 1125 */, +/* 1126 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); + +var _react = __webpack_require__(0); + +var _react2 = _interopRequireDefault(_react); + +__webpack_require__(13); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + +var IPCamPage = function (_React$Component) { + _inherits(IPCamPage, _React$Component); + + function IPCamPage() { + _classCallCheck(this, IPCamPage); + + return _possibleConstructorReturn(this, (IPCamPage.__proto__ || Object.getPrototypeOf(IPCamPage)).apply(this, arguments)); + } + + _createClass(IPCamPage, [{ + key: 'render', + value: function render() { + + return null; + } + }]); + + return IPCamPage; +}(_react2.default.Component); + +exports.default = IPCamPage; + +/***/ }), +/* 1127 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _reactRedux = __webpack_require__(30); + +var _actions = __webpack_require__(24); + +var _IPCam = __webpack_require__(1126); + +var _IPCam2 = _interopRequireDefault(_IPCam); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +var mapStateToProps = function mapStateToProps(state) { + return { + i18n: state.i18n + }; +}; + +var mapDispatchToProps = function mapDispatchToProps(dispatch, ownProps) { + return { + showDialog: function showDialog(msg) { + dispatch((0, _actions.add_dialog_msg)(msg)); + }, + toggleLoading: function toggleLoading() { + var flag = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; + + dispatch((0, _actions.toggle_loading)(flag)); + } + }; +}; + +exports.default = (0, _reactRedux.connect)(mapStateToProps, mapDispatchToProps)(_IPCam2.default); + /***/ }) /******/ ]); \ No newline at end of file diff --git a/public/locales/zh.json b/public/locales/zh.json index 92c4136..7262ac7 100644 --- a/public/locales/zh.json +++ b/public/locales/zh.json @@ -272,6 +272,7 @@ "modbus": "Modbus", "modbuscmd": "Modbus CMD", "link": "連動", + "ipcam": "網路攝影機", "logout": "登出" } }, diff --git a/route/api/system.js b/route/api/system.js index 4fb6b62..34001d7 100644 --- a/route/api/system.js +++ b/route/api/system.js @@ -393,6 +393,13 @@ router return n(); }) }) + .post('/chklogin', (req,res,n) => { + if(!tool.checkPermission(req)) return n('ERR9001'); + res.api_res = { + record: [] + } + n(); + }) .all('*', rt.send); module.exports = router; \ No newline at end of file diff --git a/src/admin.js b/src/admin.js index a71f809..209f658 100644 --- a/src/admin.js +++ b/src/admin.js @@ -8,6 +8,7 @@ import routes from './routes'; import thunk from 'redux-thunk'; import {set_i18n} from './actions'; import i18next from 'i18next'; +import {getRequest} from './actions'; const middleware = [thunk]; @@ -34,22 +35,27 @@ const store = createStore(reducers, NODE_ENV && NODE_ENV == 'production' ? apply class PageRoot extends React.Component { componentDidMount(){ - let lang = navigator - .language - .substring(0, 2); - fetch(`/locales/${lang}.json`).then(response => { - if (response.status == 200) - return response.json(); - return {} - }).then(json => { - let lang = Object.keys(json)[0] || ''; - i18next.init({ - lng: lang, - resources: json - }, () => { - store.dispatch(set_i18n(i18next)); + fetch('/api/system/chklogin', getRequest()) + .then(response=>response.json()) + .then(json => { + if(json.status != 1) return location.replace('/'); + let lang = navigator + .language + .substring(0, 2); + fetch(`/locales/${lang}.json`).then(response => { + if (response.status == 200) + return response.json(); + return {} + }).then(json => { + let lang = Object.keys(json)[0] || ''; + i18next.init({ + lng: lang, + resources: json + }, () => { + store.dispatch(set_i18n(i18next)); + }) + }) }) - }) } render() { diff --git a/src/components/MainMenu/index.js b/src/components/MainMenu/index.js index 031f3ac..b1b6025 100644 --- a/src/components/MainMenu/index.js +++ b/src/components/MainMenu/index.js @@ -18,6 +18,7 @@ const MainMenu = ({i18n, show, toggleMenu, children, permissions, showDashboard, toggleMenu()} /> toggleMenu()} /> toggleMenu()} /> + toggleMenu()} /> { sessionStorage.clear(); location.replace('/'); diff --git a/src/routes.js b/src/routes.js index ee24ef5..b34c185 100644 --- a/src/routes.js +++ b/src/routes.js @@ -13,6 +13,7 @@ import Modbus from './containers/AdminPage/Modbus'; import ModbusCmd from './containers/AdminPage/ModbusCmd'; import ActionLink from './containers/AdminPage/ActionLink'; import ActionLinkAdd from './containers/AdminPage/ActionLinkAdd'; +import IPCam from './containers/AdminPage/IPCam'; const Routes = ( @@ -28,6 +29,7 @@ const Routes = ( + );