use of com.tony.billing.entity.Admin 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;
}
use of com.tony.billing.entity.Admin in project BillingDubbo by TonyJiangWJ.
the class AuthorityInterceptor method isUserLogin.
private boolean isUserLogin(HttpServletRequest request) throws Exception {
Cookie tokenCok = CookieUtil.getCookie(CommonConstants.COOKIE_TOKEN, request);
if (tokenCok != null) {
String tokenId = authUtil.getUserTokenId(tokenCok.getValue());
Optional<Admin> store = redisUtils.get(tokenId, Admin.class);
if (store.isPresent()) {
Admin admin = store.get();
UserIdContainer.setUserId(admin.getId());
if (request instanceof TokenServletRequestWrapper) {
((TokenServletRequestWrapper) request).addParameter(CommonConstants.PARAM_TOKEN_ID, tokenId);
((TokenServletRequestWrapper) request).addParameter(CommonConstants.PARAM_USER_ID, String.valueOf(admin.getId()));
} else if (request instanceof StandardMultipartHttpServletRequest) {
((TokenServletRequestWrapper) ((StandardMultipartHttpServletRequest) request).getRequest()).addParameter("tokenId", tokenId);
((TokenServletRequestWrapper) ((StandardMultipartHttpServletRequest) request).getRequest()).addParameter("userId", String.valueOf(admin.getId()));
}
redisUtils.set(tokenId, admin, 3600 * 24);
return true;
} else {
logger.error("用户未登录:tokenId[{}]", tokenId);
}
}
return false;
}
use of com.tony.billing.entity.Admin in project BillingDubbo by TonyJiangWJ.
the class AdminServiceImpl method deleteSecret.
private Admin deleteSecret(Admin admin) {
Admin admin1 = new Admin();
admin1.setId(admin.getId());
admin1.setTokenId(admin.getTokenId());
admin1.setUserName(admin.getUserName());
admin1.setLastLogin(admin.getLastLogin());
return admin1;
}
Aggregations