Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
D
dlink
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
zhaowei
dlink
Commits
1a74cf25
Commit
1a74cf25
authored
Feb 22, 2022
by
wenmo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增用户密码修改
parent
c1ce6abb
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
187 additions
and
2 deletions
+187
-2
UserController.java
...in/src/main/java/com/dlink/controller/UserController.java
+10
-0
ModifyPasswordDTO.java
...-admin/src/main/java/com/dlink/dto/ModifyPasswordDTO.java
+18
-0
UserService.java
dlink-admin/src/main/java/com/dlink/service/UserService.java
+2
-0
UserServiceImpl.java
...src/main/java/com/dlink/service/impl/UserServiceImpl.java
+16
-0
PasswordForm.tsx
dlink-web/src/pages/user/components/PasswordForm.tsx
+111
-0
data.d.ts
dlink-web/src/pages/user/data.d.ts
+7
-0
index.tsx
dlink-web/src/pages/user/index.tsx
+23
-2
No files found.
dlink-admin/src/main/java/com/dlink/controller/UserController.java
View file @
1a74cf25
...
@@ -3,6 +3,7 @@ package com.dlink.controller;
...
@@ -3,6 +3,7 @@ package com.dlink.controller;
import
com.dlink.assertion.Asserts
;
import
com.dlink.assertion.Asserts
;
import
com.dlink.common.result.ProTableResult
;
import
com.dlink.common.result.ProTableResult
;
import
com.dlink.common.result.Result
;
import
com.dlink.common.result.Result
;
import
com.dlink.dto.ModifyPasswordDTO
;
import
com.dlink.gateway.result.TestResult
;
import
com.dlink.gateway.result.TestResult
;
import
com.dlink.model.ClusterConfiguration
;
import
com.dlink.model.ClusterConfiguration
;
import
com.dlink.model.User
;
import
com.dlink.model.User
;
...
@@ -90,4 +91,13 @@ public class UserController {
...
@@ -90,4 +91,13 @@ public class UserController {
user
=
userService
.
getById
(
user
.
getId
());
user
=
userService
.
getById
(
user
.
getId
());
return
Result
.
succeed
(
user
,
"获取成功"
);
return
Result
.
succeed
(
user
,
"获取成功"
);
}
}
/**
* 修改密码
*/
@PostMapping
(
"/modifyPassword"
)
public
Result
modifyPassword
(
@RequestBody
ModifyPasswordDTO
modifyPasswordDTO
)
{
return
userService
.
modifyPassword
(
modifyPasswordDTO
.
getUsername
(),
modifyPasswordDTO
.
getPassword
(),
modifyPasswordDTO
.
getNewPassword
());
}
}
}
dlink-admin/src/main/java/com/dlink/dto/ModifyPasswordDTO.java
0 → 100644
View file @
1a74cf25
package
com
.
dlink
.
dto
;
import
lombok.Getter
;
import
lombok.Setter
;
/**
* ModifyPasswordDTO
*
* @author wenmo
* @since 2022/2/22 23:27
*/
@Getter
@Setter
public
class
ModifyPasswordDTO
{
private
String
username
;
private
String
password
;
private
String
newPassword
;
}
dlink-admin/src/main/java/com/dlink/service/UserService.java
View file @
1a74cf25
...
@@ -16,6 +16,8 @@ public interface UserService extends ISuperService<User> {
...
@@ -16,6 +16,8 @@ public interface UserService extends ISuperService<User> {
boolean
modifyUser
(
User
user
);
boolean
modifyUser
(
User
user
);
Result
modifyPassword
(
String
username
,
String
password
,
String
newPassword
);
boolean
removeUser
(
Integer
id
);
boolean
removeUser
(
Integer
id
);
Result
loginUser
(
String
username
,
String
password
,
boolean
isRemember
);
Result
loginUser
(
String
username
,
String
password
,
boolean
isRemember
);
...
...
dlink-admin/src/main/java/com/dlink/service/impl/UserServiceImpl.java
View file @
1a74cf25
...
@@ -52,6 +52,22 @@ public class UserServiceImpl extends SuperServiceImpl<UserMapper, User> implemen
...
@@ -52,6 +52,22 @@ public class UserServiceImpl extends SuperServiceImpl<UserMapper, User> implemen
return
updateById
(
user
);
return
updateById
(
user
);
}
}
@Override
public
Result
modifyPassword
(
String
username
,
String
password
,
String
newPassword
)
{
User
user
=
getUserByUsername
(
username
);
if
(
Asserts
.
isNull
(
user
)){
return
Result
.
failed
(
"该账号不存在"
);
}
if
(!
Asserts
.
isEquals
(
SaSecureUtil
.
md5
(
password
),
user
.
getPassword
())){
return
Result
.
failed
(
"原密码错误"
);
}
user
.
setPassword
(
SaSecureUtil
.
md5
(
newPassword
));
if
(
updateById
(
user
)){
return
Result
.
succeed
(
"密码修改成功"
);
}
return
Result
.
failed
(
"密码修改失败"
);
}
@Override
@Override
public
boolean
removeUser
(
Integer
id
)
{
public
boolean
removeUser
(
Integer
id
)
{
User
user
=
new
User
();
User
user
=
new
User
();
...
...
dlink-web/src/pages/user/components/PasswordForm.tsx
0 → 100644
View file @
1a74cf25
import
React
,
{
useState
}
from
'react'
;
import
{
Form
,
Button
,
Input
,
Modal
}
from
'antd'
;
import
{
PasswordItem
}
from
"@/pages/user/data"
;
export
type
PasswordFormProps
=
{
onCancel
:
(
flag
?:
boolean
)
=>
void
;
onSubmit
:
(
values
:
Partial
<
PasswordItem
>
)
=>
void
;
modalVisible
:
boolean
;
values
:
Partial
<
PasswordItem
>
;
};
const
formLayout
=
{
labelCol
:
{
span
:
7
},
wrapperCol
:
{
span
:
13
},
};
const
PasswordForm
:
React
.
FC
<
PasswordFormProps
>
=
(
props
)
=>
{
const
[
form
]
=
Form
.
useForm
();
const
[
formVals
,
setFormVals
]
=
useState
<
Partial
<
PasswordItem
>>
({
username
:
props
.
values
.
username
,
});
const
{
onSubmit
:
handleSubmit
,
onCancel
:
handleModalVisible
,
modalVisible
,
}
=
props
;
const
submitForm
=
async
()
=>
{
const
fieldsValue
=
await
form
.
validateFields
();
setFormVals
({
...
formVals
,
...
fieldsValue
});
handleSubmit
({
...
formVals
,
...
fieldsValue
});
};
const
renderContent
=
()
=>
{
return
(
<>
<
Form
.
Item
name=
"password"
label=
"旧密码"
hasFeedback
rules=
{
[{
required
:
true
,
message
:
'请输入旧密码!'
}]
}
>
<
Input
.
Password
placeholder=
"请输入旧密码"
/>
</
Form
.
Item
>
<
Form
.
Item
name=
"newPassword"
label=
"新密码"
hasFeedback
rules=
{
[{
required
:
true
,
message
:
'请输入新密码!'
}]
}
>
<
Input
.
Password
placeholder=
"请输入新密码"
/>
</
Form
.
Item
>
<
Form
.
Item
name=
"newPasswordCheck"
label=
"重复新密码"
hasFeedback
dependencies=
{
[
'newPassword'
]
}
rules=
{
[
{
required
:
true
,
message
:
'请重复输入一致的新密码'
,
},
({
getFieldValue
})
=>
({
validator
(
_
,
value
)
{
if
(
!
value
||
getFieldValue
(
'newPassword'
)
===
value
)
{
return
Promise
.
resolve
();
}
return
Promise
.
reject
(
new
Error
(
'重复新密码不一致!'
));
},
}),
]
}
>
<
Input
.
Password
placeholder=
"请重复输入新密码"
/>
</
Form
.
Item
>
</>
);
};
const
renderFooter
=
()
=>
{
return
(
<>
<
Button
onClick=
{
()
=>
handleModalVisible
(
false
)
}
>
取消
</
Button
>
<
Button
type=
"primary"
onClick=
{
()
=>
submitForm
()
}
>
完成
</
Button
>
</>
);
};
return
(
<
Modal
width=
{
1200
}
bodyStyle=
{
{
padding
:
'32px 40px 48px'
}
}
destroyOnClose
title=
"修改密码"
visible=
{
modalVisible
}
footer=
{
renderFooter
()
}
onCancel=
{
()
=>
handleModalVisible
()
}
>
<
Form
{
...
formLayout
}
form=
{
form
}
initialValues=
{
formVals
}
>
{
renderContent
()
}
</
Form
>
</
Modal
>
);
};
export
default
PasswordForm
;
dlink-web/src/pages/user/data.d.ts
View file @
1a74cf25
...
@@ -11,3 +11,10 @@ export type UserTableListItem = {
...
@@ -11,3 +11,10 @@ export type UserTableListItem = {
worknum
?:
string
;
worknum
?:
string
;
mobile
?:
string
;
mobile
?:
string
;
};
};
export
type
PasswordItem
=
{
username
:
string
;
password
?:
string
;
newPassword
?:
string
;
newPasswordCheck
?:
string
;
};
dlink-web/src/pages/user/index.tsx
View file @
1a74cf25
...
@@ -6,8 +6,9 @@ import {FooterToolbar} from '@ant-design/pro-layout';
...
@@ -6,8 +6,9 @@ import {FooterToolbar} from '@ant-design/pro-layout';
import
ProTable
from
'@ant-design/pro-table'
;
import
ProTable
from
'@ant-design/pro-table'
;
import
ProDescriptions
from
'@ant-design/pro-descriptions'
;
import
ProDescriptions
from
'@ant-design/pro-descriptions'
;
import
{
UserTableListItem
}
from
"@/pages/user/data"
;
import
{
UserTableListItem
}
from
"@/pages/user/data"
;
import
{
handleAddOrUpdate
,
handleRemove
,
queryData
,
updateEnabled
}
from
"@/components/Common/crud"
;
import
{
handleAddOrUpdate
,
handle
Option
,
handle
Remove
,
queryData
,
updateEnabled
}
from
"@/components/Common/crud"
;
import
UserForm
from
"@/pages/user/components/UserForm"
;
import
UserForm
from
"@/pages/user/components/UserForm"
;
import
PasswordForm
from
"@/pages/user/components/PasswordForm"
;
const
url
=
'/api/user'
;
const
url
=
'/api/user'
;
const
UserTableList
:
React
.
FC
<
{}
>
=
(
props
:
any
)
=>
{
const
UserTableList
:
React
.
FC
<
{}
>
=
(
props
:
any
)
=>
{
...
@@ -15,6 +16,7 @@ const UserTableList: React.FC<{}> = (props: any) => {
...
@@ -15,6 +16,7 @@ const UserTableList: React.FC<{}> = (props: any) => {
const
[
row
,
setRow
]
=
useState
<
UserTableListItem
>
();
const
[
row
,
setRow
]
=
useState
<
UserTableListItem
>
();
const
[
modalVisible
,
handleModalVisible
]
=
useState
<
boolean
>
(
false
);
const
[
modalVisible
,
handleModalVisible
]
=
useState
<
boolean
>
(
false
);
const
[
updateModalVisible
,
handleUpdateModalVisible
]
=
useState
<
boolean
>
(
false
);
const
[
updateModalVisible
,
handleUpdateModalVisible
]
=
useState
<
boolean
>
(
false
);
const
[
passwordModalVisible
,
handlePasswordModalVisible
]
=
useState
<
boolean
>
(
false
);
const
[
formValues
,
setFormValues
]
=
useState
({});
const
[
formValues
,
setFormValues
]
=
useState
({});
const
actionRef
=
useRef
<
ActionType
>
();
const
actionRef
=
useRef
<
ActionType
>
();
const
[
selectedRowsState
,
setSelectedRows
]
=
useState
<
UserTableListItem
[]
>
([]);
const
[
selectedRowsState
,
setSelectedRows
]
=
useState
<
UserTableListItem
[]
>
([]);
...
@@ -23,6 +25,9 @@ const UserTableList: React.FC<{}> = (props: any) => {
...
@@ -23,6 +25,9 @@ const UserTableList: React.FC<{}> = (props: any) => {
if
(
key
===
'edit'
)
{
if
(
key
===
'edit'
)
{
setFormValues
(
currentItem
);
setFormValues
(
currentItem
);
handleUpdateModalVisible
(
true
);
handleUpdateModalVisible
(
true
);
}
else
if
(
key
===
'password'
)
{
setFormValues
(
currentItem
);
handlePasswordModalVisible
(
true
);
}
else
if
(
key
===
'delete'
)
{
}
else
if
(
key
===
'delete'
)
{
Modal
.
confirm
({
Modal
.
confirm
({
title
:
'删除用户'
,
title
:
'删除用户'
,
...
@@ -44,6 +49,7 @@ const UserTableList: React.FC<{}> = (props: any) => {
...
@@ -44,6 +49,7 @@ const UserTableList: React.FC<{}> = (props: any) => {
overlay=
{
overlay=
{
<
Menu
onClick=
{
({
key
})
=>
editAndDelete
(
key
,
item
)
}
>
<
Menu
onClick=
{
({
key
})
=>
editAndDelete
(
key
,
item
)
}
>
<
Menu
.
Item
key=
"edit"
>
编辑
</
Menu
.
Item
>
<
Menu
.
Item
key=
"edit"
>
编辑
</
Menu
.
Item
>
<
Menu
.
Item
key=
"password"
>
修改密码
</
Menu
.
Item
>
{
item
.
username
==
'admin'
?
''
:(<
Menu
.
Item
key=
"delete"
>
删除
</
Menu
.
Item
>)
}
{
item
.
username
==
'admin'
?
''
:(<
Menu
.
Item
key=
"delete"
>
删除
</
Menu
.
Item
>)
}
</
Menu
>
</
Menu
>
}
}
...
@@ -239,6 +245,21 @@ const UserTableList: React.FC<{}> = (props: any) => {
...
@@ -239,6 +245,21 @@ const UserTableList: React.FC<{}> = (props: any) => {
values=
{
{}
}
values=
{
{}
}
/>
/>
{
formValues
&&
Object
.
keys
(
formValues
).
length
?
(
{
formValues
&&
Object
.
keys
(
formValues
).
length
?
(
<>
<
PasswordForm
onSubmit=
{
async
(
value
)
=>
{
const
success
=
await
handleOption
(
url
+
"/modifyPassword"
,
'修改密码'
,
value
);
if
(
success
)
{
handlePasswordModalVisible
(
false
);
setFormValues
({});
}
}
}
onCancel=
{
()
=>
{
handlePasswordModalVisible
(
false
);
}
}
modalVisible=
{
passwordModalVisible
}
values=
{
formValues
}
/>
<
UserForm
<
UserForm
onSubmit=
{
async
(
value
)
=>
{
onSubmit=
{
async
(
value
)
=>
{
const
success
=
await
handleAddOrUpdate
(
"api/user"
,
value
);
const
success
=
await
handleAddOrUpdate
(
"api/user"
,
value
);
...
@@ -256,7 +277,7 @@ const UserTableList: React.FC<{}> = (props: any) => {
...
@@ -256,7 +277,7 @@ const UserTableList: React.FC<{}> = (props: any) => {
}
}
}
}
modalVisible=
{
updateModalVisible
}
modalVisible=
{
updateModalVisible
}
values=
{
formValues
}
values=
{
formValues
}
/>
/>
</>
):
null
}
):
null
}
<
Drawer
<
Drawer
width=
{
600
}
width=
{
600
}
...
...
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