Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
CivManage
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ReactWeb5
CivManage
Commits
8483c91f
Commit
8483c91f
authored
Oct 24, 2023
by
皮倩雯
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: '用户中心拆分编辑用户喝重置密码功能
parent
598f2cc7
Pipeline
#80530
passed with stages
Changes
3
Pipelines
1
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
122 additions
and
69 deletions
+122
-69
ChangePasswordModal.jsx
src/pages/userCenter/userManage/ChangePasswordModal.jsx
+107
-54
EditUserModal.jsx
src/pages/userCenter/userManage/EditUserModal.jsx
+0
-0
UserManage.jsx
src/pages/userCenter/userManage/UserManage.jsx
+15
-15
No files found.
src/pages/userCenter/userManage/ChangePasswordModal.jsx
View file @
8483c91f
/* eslint-disable import/no-unresolved */
import
React
,
{
useEffect
,
useState
}
from
'react'
;
import
{
Modal
,
Form
,
Input
,
notification
,
message
}
from
'antd'
;
import
{
updateUserPassword
}
from
'@/services/userManage/api'
;
import
sha1
from
'sha1'
;
import
{
Modal
,
Form
,
Input
,
notification
,
message
,
Divider
}
from
'antd'
;
import
voca
from
'voca'
;
import
classNames
from
'classnames'
;
import
{
editUser
,
updateUserPassword
,
GetPasswordRegularization
}
from
'@/services/userManage/api'
;
import
sha1
from
'sha1'
;
import
styles
from
'./AddUserModal.less'
;
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
(
/^
[^\u
4e00-
\u
9fa5
]
+$/
);
// 不能包含中文
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
[
newPasswordLevel
,
setNewPasswordLevel
]
=
useState
(
''
);
const
[
passwordConfirmLevel
,
setPasswordConfirmLevel
]
=
useState
(
''
);
const
[
rules
,
setRules
]
=
useState
();
useEffect
(()
=>
{
console
.
log
(
currentUser
);
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
({
oldPassword
:
currentUser
.
password
,
newPassword
:
''
,
...
...
@@ -26,6 +41,69 @@ const ChangePasswordModal = props => {
}
},
[
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
oldPassword
=
passwordForm
.
getFieldValue
(
'oldPassword'
);
...
...
@@ -39,7 +117,7 @@ const ChangePasswordModal = props => {
newPassword
===
passwordConfirm
)
{
updateUserPassword
({
UserId
:
+
currentUser
.
userI
D
,
UserId
:
+
currentUser
.
userI
d
,
OldPassWord
:
oldPassword
,
NewPassWord
:
sha1
(
newPassword
).
toUpperCase
(),
})
...
...
@@ -48,14 +126,14 @@ const ChangePasswordModal = props => {
onCancel
();
// eslint-disable-next-line no-unused-expressions
currentSelectOrg
===
'-1'
?
submitSearchUser
()
:
onSelect
([
currentSelectOrg
]);
notification
.
success
({
message
:
'提交成功'
,
duration
:
2
,
});
//
notification.success({
//
message: '提交成功',
//
duration: 2,
//
});
}
else
{
notification
.
error
({
message
:
'提交失败'
,
description
:
res
.
m
essage
,
description
:
res
.
m
sg
,
});
}
passwordForm
.
setFieldsValue
({
...
...
@@ -67,24 +145,6 @@ const ChangePasswordModal = props => {
.
catch
(
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
=>
{
...
...
@@ -123,32 +183,16 @@ const ChangePasswordModal = props => {
return
'强'
;
}
};
const
title
=
(
<
span
>
修改用户
<
span
style=
{
{
fontWeight
:
'bold'
,
color
:
'rgb(24, 144, 255)'
}
}
>
【
{
currentUser
.
userName
}
】
</
span
>
的密码
</
span
>
);
return
(
<
Modal
title=
{
title
}
visible=
{
visible
}
onOk=
{
submitChangePassword
}
maskClosable=
{
false
}
destroyOnClose
afterClose=
{
()
=>
{
passwordForm
.
resetFields
();
}
}
onOk=
{
submitEditUser
}
onCancel=
{
()
=>
{
passwordForm
.
setFieldsValue
({
oldPassword
:
currentUser
.
password
,
newPassword
:
''
,
passwordConfirm
:
''
,
});
onCancel
();
passwordForm
.
resetFields
();
}
}
okText=
"确认"
cancelText=
"取消"
...
...
@@ -163,11 +207,16 @@ const ChangePasswordModal = props => {
name=
"newPassword"
label=
"新密码"
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}
$/
,
message
:
'
长度6-16位,支持字母与数字,允许下划线'
,
pattern
:
/^
(?!
.*
(?:
SELECT|UPDATE|INSERT|AND|OR|'|"|;|--|
\\))
.*
$/
,
message
:
'
当前密码存在sql注入风险,请重新输入'
,
// 防止sql注入
},
{
required
:
true
},
//
{
required
:
true
},
]
}
>
<
Input
.
Password
...
...
@@ -198,11 +247,15 @@ const ChangePasswordModal = props => {
name=
"passwordConfirm"
label=
"确认密码"
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}
$/
,
message
:
'
长度6-16位,支持字母与数字,允许下划线'
,
pattern
:
/^
(?!
.*
(?:
SELECT|UPDATE|INSERT|AND|OR|'|"|;|--|
\\))
.*
$/
,
message
:
'
当前密码存在sql注入风险,请重新输入'
,
// 防止sql注入
},
{
required
:
true
},
]
}
>
<
Input
.
Password
...
...
src/pages/userCenter/userManage/EditUserModal.jsx
View file @
8483c91f
This diff is collapsed.
Click to expand it.
src/pages/userCenter/userManage/UserManage.jsx
View file @
8483c91f
...
...
@@ -411,12 +411,12 @@ const UserManage = () => {
/>
</Popconfirm>
</Tooltip> */
}
{
/*
<Tooltip title="修改密码">
<
Tooltip
title=
"修改密码"
>
<
UnlockOutlined
onClick=
{
()
=>
changePassword
(
record
)
}
style=
{
{
fontSize
:
'16px'
,
color
:
'#1890FF'
}
}
/>
</Tooltip>
*/
}
</
Tooltip
>
{
/* <Tooltip title="编辑用户">
<EditTwoTone onClick={() => editUser(record)} style={{ fontSize: '16px' }} />
</Tooltip> */
}
...
...
@@ -1756,20 +1756,20 @@ const UserManage = () => {
{
searchTreeValue
!==
''
?
(
<>
{
treeData
.
length
>
0
&&
(
// <div style=
{{
height
:
'100%'
,
overflowY
:
'scroll'
}}
>
<
Tree
// <div style=
{{
height
:
'100%'
,
overflowY
:
'scroll'
}}
>
<
Tree
height=
{
780
}
showIcon=
"true"
blockNode
defaultExpandAll
onSelect=
{
onSelect
}
treeData=
{
treeData
.
map
(
t
=>
mapTree
(
t
))
}
draggable
onDrop=
{
handleDrop
}
selectedKeys=
{
[
menuID
]
}
keepTree=
{
keepTree
}
/>
// </div>
showIcon=
"true"
blockNode
defaultExpandAll
onSelect=
{
onSelect
}
treeData=
{
treeData
.
map
(
t
=>
mapTree
(
t
))
}
draggable
onDrop=
{
handleDrop
}
selectedKeys=
{
[
menuID
]
}
keepTree=
{
keepTree
}
/>
// </div>
)
}
</>
)
:
(
...
...
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