Search in sources :

Example 1 with ModifyAdmin

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;
}
Also used : Admin(com.tony.billing.entity.Admin) ModifyAdmin(com.tony.billing.entity.ModifyAdmin)

Example 2 with ModifyAdmin

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);
    }
}
Also used : BaseResponse(com.tony.billing.response.BaseResponse) ModifyAdmin(com.tony.billing.entity.ModifyAdmin) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with ModifyAdmin

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();
    }
}
Also used : ModifyAdmin(com.tony.billing.entity.ModifyAdmin) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with ModifyAdmin

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;
}
Also used : BaseBusinessException(com.tony.billing.exceptions.BaseBusinessException) Admin(com.tony.billing.entity.Admin) ModifyAdmin(com.tony.billing.entity.ModifyAdmin)

Aggregations

ModifyAdmin (com.tony.billing.entity.ModifyAdmin)4 Admin (com.tony.billing.entity.Admin)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 BaseBusinessException (com.tony.billing.exceptions.BaseBusinessException)1 BaseResponse (com.tony.billing.response.BaseResponse)1