use of com.tony.billing.entity.ModifyAdmin in project BillingDubbo by TonyJiangWJ.
the class AdminServiceImpl method modifyPwd.
@Override
public boolean modifyPwd(ModifyAdmin admin) {
Preconditions.checkNotNull(admin.getId(), "用户id不能为空");
Admin dbAdmin = mapper.getAdminById(admin.getId());
if (dbAdmin == null) {
return false;
}
boolean isOldPassword = dbAdmin.getPasswordVersion() == null || dbAdmin.getPasswordVersion().equals(0);
// 现将密码进行加解密处理
admin.setNewPassword(sha256(rsaUtil.decrypt(admin.getNewPassword()), dbAdmin.getUserName()));
if (isOldPassword) {
admin.setPassword(sha256(rsaUtil.decrypt(admin.getPassword())));
} else {
admin.setPassword(sha256(rsaUtil.decrypt(admin.getPassword()), dbAdmin.getUserName()));
}
if (admin.getNewPassword() == null) {
return false;
}
Admin stored = mapper.getAdminById(admin.getId());
if (stored != null && StringUtils.equals(stored.getPassword(), admin.getPassword())) {
stored.setPassword(admin.getNewPassword());
return mapper.modifyPwd(stored) > 0;
}
logger.error("用户:{} 修改密码,旧密码不正确", admin.getId());
return false;
}
use of com.tony.billing.entity.ModifyAdmin in project BillingDubbo by TonyJiangWJ.
the class AdminController method modifyPwd.
@RequestMapping(value = "/user/pwd/modify", method = RequestMethod.POST)
public BaseResponse modifyPwd(@ModelAttribute("request") @Validated AdminModifyPwdRequest request) {
BaseResponse response = new BaseResponse();
ModifyAdmin modifyAdmin = new ModifyAdmin();
modifyAdmin.setId(request.getUserId());
modifyAdmin.setNewPassword(request.getNewPassword());
modifyAdmin.setPassword(request.getOldPassword());
if (adminService.modifyPwd(modifyAdmin)) {
return ResponseUtil.success(response);
} else {
return ResponseUtil.error(response);
}
}
use of com.tony.billing.entity.ModifyAdmin in project BillingDubbo by TonyJiangWJ.
the class AdminController method resetPassword.
@RequestMapping(value = "/user/reset/password", method = RequestMethod.POST)
public BaseResponse resetPassword(@ModelAttribute("request") @Validated ResetPasswordRequest request) {
ModifyAdmin modifyAdmin = new ModifyAdmin();
modifyAdmin.setNewPassword(request.getNewPassword());
modifyAdmin.setTokenId(request.getToken());
if (adminService.resetPwd(modifyAdmin)) {
return ResponseUtil.success();
} else {
return ResponseUtil.error();
}
}
use of com.tony.billing.entity.ModifyAdmin in project BillingDubbo by TonyJiangWJ.
the class AdminServiceImpl method resetPwd.
@Override
public boolean resetPwd(ModifyAdmin admin) {
Preconditions.checkNotNull(admin.getNewPassword(), "新密码不能为空");
String token = admin.getTokenId();
Optional<Admin> optional = redisUtils.get(token, Admin.class);
if (optional.isPresent()) {
Admin cachedUser = optional.get();
cachedUser.setPassword(sha256(rsaUtil.decrypt(admin.getNewPassword()), admin.getUserName()));
if (mapper.modifyPwd(cachedUser) > 0) {
// 密码修改完毕之后将缓存删除
redisUtils.del(token);
return true;
}
} else {
throw new BaseBusinessException("token无效,请重新申请重置密码");
}
logger.error("重置密码失败");
return false;
}
Aggregations