Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
wwwanlingxiao
mall
Commits
a1826eca
Commit
a1826eca
authored
Oct 09, 2019
by
macro
Browse files
添加修改密码接口
parent
aa60fee5
Changes
4
Hide whitespace changes
Inline
Side-by-side
mall-admin/src/main/java/com/macro/mall/controller/UmsAdminController.java
View file @
a1826eca
...
...
@@ -4,6 +4,7 @@ import com.macro.mall.common.api.CommonPage;
import
com.macro.mall.common.api.CommonResult
;
import
com.macro.mall.dto.UmsAdminLoginParam
;
import
com.macro.mall.dto.UmsAdminParam
;
import
com.macro.mall.dto.UpdateAdminPasswordParam
;
import
com.macro.mall.model.UmsAdmin
;
import
com.macro.mall.model.UmsPermission
;
import
com.macro.mall.model.UmsRole
;
...
...
@@ -126,6 +127,24 @@ public class UmsAdminController {
return
CommonResult
.
failed
();
}
@ApiOperation
(
"修改指定用户密码"
)
@RequestMapping
(
value
=
"/updatePassword"
,
method
=
RequestMethod
.
POST
)
@ResponseBody
public
CommonResult
updatePassword
(
@RequestBody
UpdateAdminPasswordParam
updatePasswordParam
)
{
int
status
=
adminService
.
updatePassword
(
updatePasswordParam
);
if
(
status
>
0
)
{
return
CommonResult
.
success
(
status
);
}
else
if
(
status
==
-
1
)
{
return
CommonResult
.
failed
(
"提交参数不合法"
);
}
else
if
(
status
==
-
2
)
{
return
CommonResult
.
failed
(
"找不到该用户"
);
}
else
if
(
status
==
-
3
)
{
return
CommonResult
.
failed
(
"旧密码错误"
);
}
else
{
return
CommonResult
.
failed
();
}
}
@ApiOperation
(
"删除指定用户信息"
)
@RequestMapping
(
value
=
"/delete/{id}"
,
method
=
RequestMethod
.
POST
)
@ResponseBody
...
...
mall-admin/src/main/java/com/macro/mall/dto/UpdateAdminPasswordParam.java
0 → 100644
View file @
a1826eca
package
com.macro.mall.dto
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Getter
;
import
lombok.Setter
;
import
org.hibernate.validator.constraints.NotEmpty
;
/**
* 修改用户名密码参数
* Created by macro on 2019/10/9.
*/
@Getter
@Setter
public
class
UpdateAdminPasswordParam
{
@ApiModelProperty
(
value
=
"用户名"
,
required
=
true
)
private
String
username
;
@ApiModelProperty
(
value
=
"旧密码"
,
required
=
true
)
private
String
oldPassword
;
@ApiModelProperty
(
value
=
"新密码"
,
required
=
true
)
private
String
newPassword
;
}
mall-admin/src/main/java/com/macro/mall/service/UmsAdminService.java
View file @
a1826eca
package
com.macro.mall.service
;
import
com.macro.mall.dto.UmsAdminParam
;
import
com.macro.mall.dto.UpdateAdminPasswordParam
;
import
com.macro.mall.model.UmsAdmin
;
import
com.macro.mall.model.UmsPermission
;
import
com.macro.mall.model.UmsRole
;
...
...
@@ -78,4 +79,9 @@ public interface UmsAdminService {
* 获取用户所有权限(包括角色权限和+-权限)
*/
List
<
UmsPermission
>
getPermissionList
(
Long
adminId
);
/**
* 修改密码
*/
int
updatePassword
(
UpdateAdminPasswordParam
updatePasswordParam
);
}
mall-admin/src/main/java/com/macro/mall/service/impl/UmsAdminServiceImpl.java
View file @
a1826eca
package
com.macro.mall.service.impl
;
import
cn.hutool.core.collection.CollUtil
;
import
cn.hutool.core.util.StrUtil
;
import
com.github.pagehelper.PageHelper
;
import
com.macro.mall.dao.UmsAdminPermissionRelationDao
;
import
com.macro.mall.dao.UmsAdminRoleRelationDao
;
import
com.macro.mall.dto.UmsAdminParam
;
import
com.macro.mall.dto.UpdateAdminPasswordParam
;
import
com.macro.mall.mapper.UmsAdminLoginLogMapper
;
import
com.macro.mall.mapper.UmsAdminMapper
;
import
com.macro.mall.mapper.UmsAdminPermissionRelationMapper
;
...
...
@@ -249,4 +252,26 @@ public class UmsAdminServiceImpl implements UmsAdminService {
public
List
<
UmsPermission
>
getPermissionList
(
Long
adminId
)
{
return
adminRoleRelationDao
.
getPermissionList
(
adminId
);
}
@Override
public
int
updatePassword
(
UpdateAdminPasswordParam
param
)
{
if
(
StrUtil
.
isEmpty
(
param
.
getUsername
())
||
StrUtil
.
isEmpty
(
param
.
getOldPassword
())
||
StrUtil
.
isEmpty
(
param
.
getNewPassword
())){
return
-
1
;
}
UmsAdminExample
example
=
new
UmsAdminExample
();
example
.
createCriteria
().
andUsernameEqualTo
(
param
.
getUsername
());
List
<
UmsAdmin
>
adminList
=
adminMapper
.
selectByExample
(
example
);
if
(
CollUtil
.
isEmpty
(
adminList
)){
return
-
2
;
}
UmsAdmin
umsAdmin
=
adminList
.
get
(
0
);
if
(!
passwordEncoder
.
matches
(
param
.
getOldPassword
(),
umsAdmin
.
getPassword
())){
return
-
3
;
}
umsAdmin
.
setPassword
(
passwordEncoder
.
encode
(
param
.
getNewPassword
()));
adminMapper
.
updateByPrimaryKey
(
umsAdmin
);
return
1
;
}
}
Write
Preview
Supports
Markdown
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