Search in sources :

Example 6 with Admin

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

Example 7 with Admin

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;
}
Also used : Cookie(javax.servlet.http.Cookie) StandardMultipartHttpServletRequest(org.springframework.web.multipart.support.StandardMultipartHttpServletRequest) Admin(com.tony.billing.entity.Admin) TokenServletRequestWrapper(com.tony.billing.filters.wapper.TokenServletRequestWrapper)

Example 8 with Admin

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

Aggregations

Admin (com.tony.billing.entity.Admin)8 ModifyAdmin (com.tony.billing.entity.ModifyAdmin)7 BaseBusinessException (com.tony.billing.exceptions.BaseBusinessException)2 BaseResponse (com.tony.billing.response.BaseResponse)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 TokenServletRequestWrapper (com.tony.billing.filters.wapper.TokenServletRequestWrapper)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 MessagingException (javax.mail.MessagingException)1 Cookie (javax.servlet.http.Cookie)1 StandardMultipartHttpServletRequest (org.springframework.web.multipart.support.StandardMultipartHttpServletRequest)1