Commit 8483c91f authored by 皮倩雯's avatar 皮倩雯

fix: '用户中心拆分编辑用户喝重置密码功能

parent 598f2cc7
Pipeline #80530 passed with stages
/* eslint-disable import/no-unresolved */ /* eslint-disable import/no-unresolved */
import React, { useEffect, useState } from 'react'; import React, { useEffect, useState } from 'react';
import { Modal, Form, Input, notification, message } from 'antd'; import { Modal, Form, Input, notification, message, Divider } from 'antd';
import { updateUserPassword } from '@/services/userManage/api'; import voca from 'voca';
import sha1 from 'sha1';
import classNames from 'classnames'; import classNames from 'classnames';
import { editUser, updateUserPassword, GetPasswordRegularization } from '@/services/userManage/api';
import sha1 from 'sha1';
import styles from './AddUserModal.less'; import styles from './AddUserModal.less';
const ChangePasswordModal = props => { const ChangePasswordModal = props => {
const { visible, currentUser, currentSelectOrg, submitSearchUser, onSelect, onCancel } = props; const { visible, currentUser, currentSelectOrg, onCancel, onSelect, submitSearchUser } = props;
const [editUserForm] = Form.useForm(); // 编辑用户
/** ***正则验证**** */
const noChinese = new RegExp(/^[^\u4e00-\u9fa5]+$/); // 不能包含中文
const isPhone = new RegExp(/^1(3|4|5|6|7|8|9)\d{9}$/); // 手机号
const isEmail = new RegExp(
/^[a-zA-Z0-9]+([-_.][a-zA-Z0-9]+)*@[a-zA-Z0-9]+([-_.][a-zA-Z0-9]+)*\.[a-z]{2,}$/,
); // 邮箱
const [passwordForm] = Form.useForm(); // 修改密码 const [passwordForm] = Form.useForm(); // 修改密码
const [newPasswordLevel, setNewPasswordLevel] = useState(''); const [newPasswordLevel, setNewPasswordLevel] = useState('');
const [passwordConfirmLevel, setPasswordConfirmLevel] = useState(''); const [passwordConfirmLevel, setPasswordConfirmLevel] = useState('');
const [rules, setRules] = useState();
useEffect(() => { useEffect(() => {
console.log(currentUser);
if (visible) { if (visible) {
console.log(currentUser.password); getPasswordRule();
editUserForm.setFieldsValue({
loginName: voca.stripTags(currentUser.loginName),
userName: voca.stripTags(currentUser.userName),
phone: voca.stripTags(currentUser.phone) || '',
email: currentUser.email || '',
});
passwordForm.setFieldsValue({ passwordForm.setFieldsValue({
oldPassword: currentUser.password, oldPassword: currentUser.password,
newPassword: '', newPassword: '',
...@@ -26,6 +41,69 @@ const ChangePasswordModal = props => { ...@@ -26,6 +41,69 @@ const ChangePasswordModal = props => {
} }
}, [visible]); }, [visible]);
const getPasswordRule = () => {
GetPasswordRegularization().then(res => {
if (res.code === 0) {
setRules(res.data);
}
});
};
// 提交-编辑用户
const submitEditUser = () => {
const newPassword = passwordForm.getFieldValue('newPassword');
const passwordConfirm = passwordForm.getFieldValue('passwordConfirm');
passwordForm.validateFields().then(validate => {
if (validate) {
if ((newPassword && newPassword.length < 6) || (passwordConfirm && passwordConfirm < 6)) {
notification.error({
message: '提交失败',
description: '密码至少为6位!',
});
return;
}
if (newPassword !== passwordConfirm) {
notification.error({
message: '提交失败',
description: '确认密码不一致!',
});
return;
}
if (newPassword && newPassword) {
if (newPasswordLevel === '弱') {
notification.error({
message: '提交失败',
description: '密码强度太弱,加强密码强度',
});
return;
}
if (
!/^(?=.*[a-zA-Z])(?=.*\d)[\w\S]{6,16}$/.test(newPassword) ||
!/^(?!.*(?:SELECT|UPDATE|INSERT|AND|OR|'|"|;|--|\\)).*$/.test(newPassword)
) {
notification.error({
message: '提交失败',
description: '密码验证未通过',
});
return;
}
}
// 所有验证通过才可以提交,phone/email为空时不验证
submitChangePassword();
}
});
};
const title = (
<span>
重置用户
<span style={{ fontWeight: 'bold', color: 'rgb(24, 144, 255)' }}>
{currentUser.userName}
</span>
的密码
</span>
);
// 提交-修改密码 // 提交-修改密码
const submitChangePassword = () => { const submitChangePassword = () => {
const oldPassword = passwordForm.getFieldValue('oldPassword'); const oldPassword = passwordForm.getFieldValue('oldPassword');
...@@ -39,7 +117,7 @@ const ChangePasswordModal = props => { ...@@ -39,7 +117,7 @@ const ChangePasswordModal = props => {
newPassword === passwordConfirm newPassword === passwordConfirm
) { ) {
updateUserPassword({ updateUserPassword({
UserId: +currentUser.userID, UserId: +currentUser.userId,
OldPassWord: oldPassword, OldPassWord: oldPassword,
NewPassWord: sha1(newPassword).toUpperCase(), NewPassWord: sha1(newPassword).toUpperCase(),
}) })
...@@ -48,14 +126,14 @@ const ChangePasswordModal = props => { ...@@ -48,14 +126,14 @@ const ChangePasswordModal = props => {
onCancel(); onCancel();
// eslint-disable-next-line no-unused-expressions // eslint-disable-next-line no-unused-expressions
currentSelectOrg === '-1' ? submitSearchUser() : onSelect([currentSelectOrg]); currentSelectOrg === '-1' ? submitSearchUser() : onSelect([currentSelectOrg]);
notification.success({ // notification.success({
message: '提交成功', // message: '提交成功',
duration: 2, // duration: 2,
}); // });
} else { } else {
notification.error({ notification.error({
message: '提交失败', message: '提交失败',
description: res.message, description: res.msg,
}); });
} }
passwordForm.setFieldsValue({ passwordForm.setFieldsValue({
...@@ -67,24 +145,6 @@ const ChangePasswordModal = props => { ...@@ -67,24 +145,6 @@ const ChangePasswordModal = props => {
.catch(err => { .catch(err => {
message.error(err); message.error(err);
}); });
} else if (newPassword === '' || passwordConfirm === '') {
notification.error({
message: '提交失败',
description: '带*号为必填项,不能为空',
});
} else if (
(newPassword && newPassword.length < 6) ||
(passwordConfirm && passwordConfirm < 6)
) {
notification.error({
message: '提交失败',
description: '密码至少为6位!',
});
} else if (newPassword !== passwordConfirm) {
notification.error({
message: '提交失败',
description: '确认密码不一致!',
});
} }
}; };
const changeValue = changedFields => { const changeValue = changedFields => {
...@@ -123,32 +183,16 @@ const ChangePasswordModal = props => { ...@@ -123,32 +183,16 @@ const ChangePasswordModal = props => {
return '强'; return '强';
} }
}; };
const title = (
<span>
修改用户
<span style={{ fontWeight: 'bold', color: 'rgb(24, 144, 255)' }}>
{currentUser.userName}
</span>
的密码
</span>
);
return ( return (
<Modal <Modal
title={title} title={title}
visible={visible} visible={visible}
onOk={submitChangePassword}
maskClosable={false} maskClosable={false}
destroyOnClose destroyOnClose
afterClose={() => { onOk={submitEditUser}
passwordForm.resetFields();
}}
onCancel={() => { onCancel={() => {
passwordForm.setFieldsValue({
oldPassword: currentUser.password,
newPassword: '',
passwordConfirm: '',
});
onCancel(); onCancel();
passwordForm.resetFields();
}} }}
okText="确认" okText="确认"
cancelText="取消" cancelText="取消"
...@@ -163,11 +207,16 @@ const ChangePasswordModal = props => { ...@@ -163,11 +207,16 @@ const ChangePasswordModal = props => {
name="newPassword" name="newPassword"
label="新密码" label="新密码"
rules={[ rules={[
{ required: true, message: '请输入密码' },
{ {
pattern: /^[a-zA-Z0-9_]{6,16}$/, pattern: rules ? rules.regex : `/^(?=.*[a-zA-Z])(?=.*d)[wS]{6,16}$/`,
message: '长度6-16位,支持字母与数字,允许下划线', message: rules ? rules.tip : '长度6-16位,必须包含数字与字母',
}, },
{ required: true }, {
pattern: /^(?!.*(?:SELECT|UPDATE|INSERT|AND|OR|'|"|;|--|\\)).*$/,
message: '当前密码存在sql注入风险,请重新输入', // 防止sql注入
},
// { required: true },
]} ]}
> >
<Input.Password <Input.Password
...@@ -198,11 +247,15 @@ const ChangePasswordModal = props => { ...@@ -198,11 +247,15 @@ const ChangePasswordModal = props => {
name="passwordConfirm" name="passwordConfirm"
label="确认密码" label="确认密码"
rules={[ rules={[
{ required: true, message: '请输入密码' },
{
pattern: rules ? rules.regex : `/^(?=.*[a-zA-Z])(?=.*d)[wS]{6,16}$/`,
message: rules ? rules.tip : '长度6-16位,必须包含数字与字母',
},
{ {
pattern: /^[a-zA-Z0-9_]{6,16}$/, pattern: /^(?!.*(?:SELECT|UPDATE|INSERT|AND|OR|'|"|;|--|\\)).*$/,
message: '长度6-16位,支持字母与数字,允许下划线', message: '当前密码存在sql注入风险,请重新输入', // 防止sql注入
}, },
{ required: true },
]} ]}
> >
<Input.Password <Input.Password
......
...@@ -411,12 +411,12 @@ const UserManage = () => { ...@@ -411,12 +411,12 @@ const UserManage = () => {
/> />
</Popconfirm> </Popconfirm>
</Tooltip> */} </Tooltip> */}
{/* <Tooltip title="修改密码"> <Tooltip title="修改密码">
<UnlockOutlined <UnlockOutlined
onClick={() => changePassword(record)} onClick={() => changePassword(record)}
style={{ fontSize: '16px', color: '#1890FF' }} style={{ fontSize: '16px', color: '#1890FF' }}
/> />
</Tooltip> */} </Tooltip>
{/* <Tooltip title="编辑用户"> {/* <Tooltip title="编辑用户">
<EditTwoTone onClick={() => editUser(record)} style={{ fontSize: '16px' }} /> <EditTwoTone onClick={() => editUser(record)} style={{ fontSize: '16px' }} />
</Tooltip> */} </Tooltip> */}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment