| | |
| | | package com.doumee.config.Jwt; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.doumee.config.annotation.LoginRequired; |
| | | import com.doumee.config.annotation.LoginShopRequired; |
| | | import com.doumee.core.constants.ResponseStatus; |
| | | import com.doumee.core.exception.BusinessException; |
| | | import com.doumee.core.utils.Constants; |
| | | import com.doumee.dao.business.model.Member; |
| | | import com.doumee.dao.business.model.Shop; |
| | | import io.jsonwebtoken.JwtException; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.lang.reflect.Method; |
| | | import java.util.Objects; |
| | | |
| | | @Configuration |
| | | public class WebMvcConfig implements WebMvcConfigurer { |
| | |
| | | if(StringUtils.isBlank(tokenRedis)){ |
| | | throw new BusinessException(ResponseStatus.NO_LOGIN.getCode(),"未登录"); |
| | | } |
| | | Member member = JSONObject.parseObject(tokenRedis, Member.class); |
| | | if(Objects.isNull(member)||StringUtils.isBlank(member.getOpenId())){ |
| | | throw new BusinessException(ResponseStatus.NO_LOGIN.getCode(),"未登录"); |
| | | } |
| | | String openid = member.getOpenId(); |
| | | Integer memberId = getTokenId(token); |
| | | Integer isDeleted = dao.queryForObject(" select COALESCE(ISDELETED,0) from Member where id = ?", Integer.class, memberId); |
| | | Integer isDeleted = dao.queryForObject(" select COALESCE(ISDELETED,0) from member where id = ?", Integer.class, memberId); |
| | | if(isDeleted== Constants.ONE){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"用户已删除,请联系管理员"); |
| | | } |
| | | Integer isForbidden = dao.queryForObject(" select COALESCE(STATUS,0) from Member where id = ?", Integer.class, memberId); |
| | | if(isForbidden== Constants.ONE){ |
| | | Integer isForbidden = dao.queryForObject(" select COALESCE(STATUS,0) from member where id = ?", Integer.class, memberId); |
| | | if(isForbidden == Constants.ONE){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"用户已禁用,请联系管理员"); |
| | | } |
| | | Integer count = dao.queryForObject("select count(1) from Member where id = ?", Integer.class, memberId); |
| | | if(isForbidden == Constants.TWO){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"用户已注销,请联系管理员"); |
| | | } |
| | | String dbOpenid = dao.queryForObject(" select ifnull(open_id,'') from member where id = ?", String.class, memberId); |
| | | if(StringUtils.isBlank(dbOpenid)||!openid.equals(dbOpenid)){ |
| | | throw new BusinessException(ResponseStatus.NO_LOGIN.getCode(),"已过期,请重新登录"); |
| | | } |
| | | Integer count = dao.queryForObject("select count(1) from member where id = ?", Integer.class, memberId); |
| | | if (count != null && count > 0) { |
| | | request.setAttribute(JwtTokenUtil.UserId_Name, memberId); |
| | | return true; |
| | |
| | | if(StringUtils.isBlank(tokenRedis)){ |
| | | throw new BusinessException(ResponseStatus.NO_LOGIN.getCode(),"未登录"); |
| | | } |
| | | Shop shop = JSONObject.parseObject(tokenRedis, Shop.class); |
| | | if(Objects.isNull(shop)||StringUtils.isBlank(shop.getOpenId())){ |
| | | throw new BusinessException(ResponseStatus.NO_LOGIN.getCode(),"未登录"); |
| | | } |
| | | String openid = shop.getOpenId(); |
| | | Integer shopId = getTokenId(token); |
| | | Integer isDeleted = dao.queryForObject(" select COALESCE(ISDELETED,0) from shop where id = ?", Integer.class, shopId); |
| | | if(isDeleted== Constants.ONE){ |
| | |
| | | Integer isForbidden = dao.queryForObject(" select COALESCE(STATUS,0) from shop where id = ?", Integer.class, shopId); |
| | | if(isForbidden== Constants.ONE){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"用户已禁用,请联系管理员"); |
| | | } |
| | | String dbOpenid = dao.queryForObject(" select ifnull(open_id,'') from shop where id = ?", String.class, shopId); |
| | | if(StringUtils.isBlank(dbOpenid)||!openid.equals(dbOpenid)){ |
| | | throw new BusinessException(ResponseStatus.NO_LOGIN.getCode(),"已过期,请重新登录"); |
| | | } |
| | | Integer count = dao.queryForObject("select count(1) from shop where id = ?", Integer.class, shopId); |
| | | if (count != null && count > 0) { |
| | |
| | | throw new BusinessException(ResponseStatus.NO_LOGIN.getCode(),"未登录"); |
| | | } |
| | | } |
| | | |
| | | |
| | | public Integer getTokenId(String token){ |
| | | try { |