Browse Source

免密登录 100%

master
wenlele 2 years ago
parent
commit
7629ba2dec
  1. 42
      web/client/src/layout/containers/layout/index.jsx
  2. 6
      web/client/src/sections/auth/actions/auth.js
  3. 2
      web/client/src/sections/auth/containers/login.jsx
  4. 15
      web/client/src/sections/humanAffairs/components/deleteModal.jsx
  5. 8
      web/config.js
  6. 2
      web/package.json

42
web/client/src/layout/containers/layout/index.jsx

@ -13,6 +13,9 @@ import { useLocation } from "react-router";
import { RouteTable } from '$utils';
import { RouteRequest } from '@peace/utils';
import Cookie from 'js-cookie';
import { login, LOGIN_SUCCESS } from '../../../sections/auth/actions/auth';
import { error } from 'webpack-dev-server/lib/utils/colors';
NProgress.configure({
@ -31,8 +34,8 @@ let requestUser = true
// const location111 = useLocation();
const LayoutContainer = props => {
const {
dispatch, msg, user, copyright, children, sections, clientWidth, clientHeight,
location, match, routes, history, socket,
dispatch, actions, msg, user, copyright, children, sections, clientWidth, clientHeight,
location, match, routes, history, socket,apiRoot
} = props
const [collapsed, setCollapsed] = useState(false)
@ -205,32 +208,20 @@ const LayoutContainer = props => {
if (requestUser) {
requestUser = false;
RouteRequest.get(RouteTable.getDomain).then(res => {
console.log(res);
let token = Cookie.get('pepToken', { domain: res.root });
dispatch(login({ token })).then(res => {
if (res.type == 'LOGIN_SUCCESS') {
const data = res.payload?.user || {}
history.push('/humanAffairs/archivesCenter/personnelArchives/personnelFiles')
dispatch(login(values.username, values.password)).then(res => {
const data = res.payload.user
localStorage.setItem('word', JSON.stringify(values.password))
localStorage.setItem('poms_open_sider', JSON.stringify(["archivesCenter"]))
localStorage.setItem('poms_selected_sider', JSON.stringify(["humanAffairs"]))
dispatch(actions.layout.initWebSocket({ ioUrl: apiRoot, token: data.token, hrUserId: data.hrUserInfo && hrUserInfo.id }))
} else {
redirectToLogin(true);
}
}, error => {
redirectToLogin(true);
})
// dispatch(getUserInfoByTokenUrl(token)).then(userRes => {
// if (userRes.success) {
// sessionStorage.setItem('user', JSON.stringify(userRes.payload.data));
// dispatch({
// type: 'INIT_AUTH',
// payload: {
// user: userRes.payload.data
// }
// })
// // window.location.href = window.location.href;
// } else {
// redirectToLogin(true);
// }
// }, error => {
// redirectToLogin(true);
// })
}, error => {
message.error('鉴权失败', 5);
redirectToLogin(true);
@ -378,7 +369,8 @@ function mapStateToProps (state) {
clientHeight: global.clientHeight,
msg: ajaxResponse.msg,
user: auth.user,
socket: webSocket.socket
socket: webSocket.socket,
apiRoot: global.apiRoot,
};
}

6
web/client/src/sections/auth/actions/auth.js

@ -21,11 +21,11 @@ export function initAuth(userData) {
export const REQUEST_LOGIN = 'REQUEST_LOGIN';
export const LOGIN_SUCCESS = 'LOGIN_SUCCESS';
export const LOGIN_ERROR = 'LOGIN_ERROR';
export function login(username, password) {
export function login ({ username, password, token }) {
return dispatch => {
dispatch({ type: REQUEST_LOGIN });
if (!username || !password) {
if ((!username || !password) && !token) {
dispatch({
type: LOGIN_ERROR,
payload: { error: '请输入账号名和密码' }
@ -43,7 +43,7 @@ export function login(username, password) {
// },
// });
return Request.post(ApiTable.login, { username, password, code: 'HR' })
return Request.post(ApiTable.login, { username, password, token, code: 'HR' })
.then(user => {
sessionStorage.setItem('hrUser', JSON.stringify(user));
return dispatch({

2
web/client/src/sections/auth/containers/login.jsx

@ -64,7 +64,7 @@ const Login = props => {
</div>
<Form
onSubmit={values => {
dispatch(login(values.username, values.password)).then(res => {
dispatch(login({ username: values.username, password: values.password })).then(res => {
const data = res.payload.user
localStorage.setItem('word', JSON.stringify(values.password))
dispatch(actions.layout.initWebSocket({ ioUrl: apiRoot, token: data.token, hrUserId: data.hrUserInfo && hrUserInfo.id }))

15
web/client/src/sections/humanAffairs/components/deleteModal.jsx

@ -3,6 +3,7 @@ import { connect } from "react-redux";
import { Modal, Form, Button, Upload, Toast } from "@douyinfe/semi-ui";
import { IconAlertCircle } from '@douyinfe/semi-icons';
import cityData from './city.json';
import { ApiTable, AxyRequest, EmisRequest } from '$utils'
import PerfectScrollbar from "perfect-scrollbar";
import './style.less'
let Scrollbar;
@ -13,7 +14,8 @@ function deleteModal (props) {
visible,
dispatch,
actions,
pepUserId
pepUserId,
user
} = props;
const { humanAffairs } = actions;
const form = useRef();//
@ -42,18 +44,17 @@ function deleteModal (props) {
form.current
.validate()
.then((values) => {
if (word == values.word) {
console.log(values);
let data = EmisRequest?.post(`verify/user/${user?.id}/pswd`, { pswd: values?.word }, { token: user?.token }).then(res => {
dispatch(humanAffairs.delMember({ pepUserId: pepUserId, msg: '删除档案' })).then((res) => {//(PEP)
if (res.success) {
close();
}
})
}
else {
Toast.error('密码错误');
}, err => {
Toast.error(err?.response?.body?.message || '密码错误')
form.current.setValue('word', '')
}
})
})
}
function handleCancel () {

8
web/config.js

@ -13,6 +13,7 @@ dev && console.log('\x1B[33m%s\x1b[0m', '请遵循并及时更新 readme.md,
args.option(['p', 'port'], '启动端口');
args.option(['u', 'api-url'], 'webapi的URL');
args.option('apiHrUrl', 'webapi的URL 外网可访问');
args.option('apiEmisUrl', '企业管理 api');
args.option(['d', 'domain'], 'web domain');
@ -32,6 +33,7 @@ const flags = args.parse(process.argv);
const API_URL = process.env.API_URL || flags.apiUrl;
const API_HR_URL = process.env.API_HR_URL || flags.apiHrUrl;
const FS_HR_DOMAIN = process.env.FS_HR_DOMAIN || flags.domain;
const API_EMIS_URL = process.env.API_EMIS_URL || flags.apiEmisUrl;
// 七牛
const ANXINCLOUD_QINIU_AK = process.env.ANXINCLOUD_QINIU_ACCESSKEY || flags.qnak;
@ -88,6 +90,12 @@ const product = {
},
domain: FS_HR_DOMAIN,
}
}, {
entry: require('./middlewares/proxy').entry,
opts: {
host: API_EMIS_URL,
match: /^\/_emis\//,
}
}, {
entry: require('./client').entry,// 静态信息
opts: {}

2
web/package.json

@ -7,7 +7,7 @@
"test": "mocha",
"start-vite": "cross-env NODE_ENV=developmentVite npm run start-params",
"start": "cross-env NODE_ENV=development npm run start-params",
"start-params": "node server -p 5700 -u http://localhost:4700 --apiHrUrl http://localhost:4700 -d localhost --qnak XuDgkao6cL0HidoMAPnA5OB10Mc_Ew08mpIfRJK5 --qnsk yewcieZLzKZuDfig0wLZ9if9jKp2P_1jd3CMJPSa --qnbkt dev-hr --qndmn http://rjkwed13l.hn-bkt.clouddn.com --wkys http://10.8.30.109:14000",
"start-params": "node server -p 5700 -u http://localhost:4700 --apiHrUrl http://localhost:4700 -d localhost --apiEmisUrl http://localhost:4000 --qnak XuDgkao6cL0HidoMAPnA5OB10Mc_Ew08mpIfRJK5 --qnsk yewcieZLzKZuDfig0wLZ9if9jKp2P_1jd3CMJPSa --qnbkt dev-hr --qndmn http://rjkwed13l.hn-bkt.clouddn.com --wkys http://10.8.30.109:14000",
"deploy": "export NODE_ENV=production&& npm run build && node server",
"build-dev": "cross-env NODE_ENV=development&&webpack --config webpack.config.js",
"build": "cross-env NODE_ENV=production&&webpack --config webpack.config.prod.js"

Loading…
Cancel
Save