| | |
| | | package com.doumee.api; |
| | | |
| | | import com.doumee.config.annotation.LoginNoRequired; |
| | | import com.doumee.config.jwt.JwtProperties; |
| | | import com.doumee.config.jwt.JwtTokenUtil; |
| | | import com.doumee.core.annotation.pr.PreventRepeat; |
| | |
| | | import com.doumee.core.exception.BusinessException; |
| | | import com.doumee.core.model.ApiResponse; |
| | | import com.doumee.core.model.LoginUserInfo; |
| | | import com.doumee.core.utils.Constants; |
| | | import com.doumee.dao.system.dto.LoginDTO; |
| | | import com.doumee.service.system.SystemLoginService; |
| | | import com.doumee.service.system.SystemUserService; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiModel; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.http.server.reactive.ServerHttpRequest; |
| | |
| | | * JWT获取令牌和刷新令牌接口 |
| | | */ |
| | | @RestController |
| | | @Api("鉴权登录接口") |
| | | @Api(tags ="鉴权登录接口") |
| | | public class JwtAuthController { |
| | | |
| | | @Resource |
| | |
| | | @PreventRepeat(limit = 10, lockTime = 10000) |
| | | @ApiOperation("登录") |
| | | @PostMapping("/login") |
| | | @LoginNoRequired |
| | | public ApiResponse<String> login (@Validated @RequestBody LoginDTO dto, ServerWebExchange serverWebExchange) { |
| | | try { |
| | | ServerHttpRequest request = serverWebExchange.getRequest(); |
| | |
| | | * 刷新JWT令牌,用旧的令牌换新的令牌 |
| | | */ |
| | | @PostMapping("/refreshtoken") |
| | | @ApiOperation("刷新token") |
| | | public ApiResponse<String> refreshtoken(@RequestHeader("userToken") String oldToken){ |
| | | try { |
| | | if(!jwtTokenUtil.isTokenExpired(oldToken)){ |
| | |
| | | * 刷新JWT令牌,用旧的令牌换新的令牌 |
| | | */ |
| | | @GetMapping("/getUserInfo") |
| | | public ApiResponse<LoginUserInfo> getUserInfo(@RequestHeader("userToken") String token){ |
| | | @ApiOperation("获取当前登陆用户") |
| | | public ApiResponse<LoginUserInfo> getUserInfo(@RequestHeader(Constants.HEADER_USER_TOKEN) String token){ |
| | | try { |
| | | LoginUserInfo user =jwtTokenUtil.getUserInfoByToken(token); |
| | | if(user !=null){ |