| | |
| | | package com.doumee.config.jwt; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.doumee.core.annotation.LoginRequired; |
| | | import com.doumee.core.constants.Constants; |
| | | import com.doumee.config.annotation.LoginRequired; |
| | | import com.doumee.core.constants.ResponseStatus; |
| | | import com.doumee.core.exception.BusinessException; |
| | | import com.doumee.dao.business.model.Member; |
| | | import com.doumee.dao.vo.WebLoginUserVO; |
| | | import io.jsonwebtoken.JwtException; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | public Boolean checkLogin(HttpServletRequest request, HttpServletResponse response){ |
| | | String token = request.getHeader(JwtTokenUtil.HEADER_KEY); |
| | | try { |
| | | Member member = jwtTokenUtil.getUserInfoByToken(token); |
| | | if(Objects.isNull(member)){ |
| | | WebLoginUserVO webLoginUserVO = jwtTokenUtil.getUserInfoByToken(token); |
| | | if(Objects.isNull(webLoginUserVO)){ |
| | | throw new BusinessException(ResponseStatus.TOKEN_EXCEED_TIME.getCode(),"长时间未操作,请重新登录"); |
| | | } |
| | | Integer isDeleted = dao.queryForObject(" select COALESCE(DELETED,1) from member where id = ?", Integer.class, member.getId()); |
| | | if(isDeleted.equals(Constants.ONE)){ |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"用户已删除,请联系管理员"); |
| | | } |
| | | Integer count = dao.queryForObject("select count(1) from member where id = ?", Integer.class, member.getId()); |
| | | if (count != null && count > 0) { |
| | | // jwtTokenUtil.refreshToken(token,member); |
| | | request.setAttribute(JwtTokenUtil.MEMBER_INFO, JSONObject.toJSONString(member)); |
| | | request.setAttribute(JwtTokenUtil.MEMBER_ID, member.getId()); |
| | | request.setAttribute(JwtTokenUtil.MEMBER_INFO, JSONObject.toJSONString(webLoginUserVO)); |
| | | request.setAttribute(JwtTokenUtil.MEMBER_ID, webLoginUserVO.getId()); |
| | | return true; |
| | | }else{ |
| | | throw new BusinessException(ResponseStatus.BE_OVERDUE.getCode(),"用户信息出错"); |
| | | } |
| | | } catch (IllegalArgumentException | JwtException e) { |
| | | throw new BusinessException(ResponseStatus.BE_OVERDUE.getCode(),"未登录"); |
| | | } |