|  |  |  | 
|---|
|  |  |  | import com.doumee.core.model.LoginUserInfo; | 
|---|
|  |  |  | import com.doumee.core.utils.Constants; | 
|---|
|  |  |  | import com.doumee.dao.system.dto.LoginDTO; | 
|---|
|  |  |  | import com.doumee.dao.system.dto.LoginPhoneDTO; | 
|---|
|  |  |  | import com.doumee.service.common.CaptchaService; | 
|---|
|  |  |  | import com.doumee.service.system.SystemLoginService; | 
|---|
|  |  |  | import com.doumee.service.system.SystemUserService; | 
|---|
|  |  |  | 
|---|
|  |  |  | import org.springframework.web.server.ServerWebExchange; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import javax.annotation.Resource; | 
|---|
|  |  |  | import java.util.Objects; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * JWT获取令牌和刷新令牌接口 | 
|---|
|  |  |  | 
|---|
|  |  |  | public ApiResponse<String> login (@Validated @RequestBody LoginDTO dto, ServerWebExchange serverWebExchange) { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | ServerHttpRequest request = serverWebExchange.getRequest(); | 
|---|
|  |  |  | dto.setCheckCode(true); | 
|---|
|  |  |  | LoginUserInfo user = systemLoginService.loginByPasswordNew(dto,request); | 
|---|
|  |  |  | String token = jwtTokenUtil.generateToken(user); | 
|---|
|  |  |  | return ApiResponse.success(token); | 
|---|
|  |  |  | 
|---|
|  |  |  | return ApiResponse.failed(ResponseStatus.SERVER_ERROR); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PreventRepeat(limit = 10, lockTime = 10000) | 
|---|
|  |  |  | @ApiOperation("短信验证码登录") | 
|---|
|  |  |  | @PostMapping("/loginByPhone") | 
|---|
|  |  |  | @LoginNoRequired | 
|---|
|  |  |  | public ApiResponse<String> loginByPhone (@Validated @RequestBody LoginPhoneDTO dto, ServerWebExchange serverWebExchange) { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | ServerHttpRequest request = serverWebExchange.getRequest(); | 
|---|
|  |  |  | LoginUserInfo user = systemLoginService.loginByPhone(dto,request); | 
|---|
|  |  |  | String token = jwtTokenUtil.generateToken(user); | 
|---|
|  |  |  | return ApiResponse.success(token); | 
|---|
|  |  |  | }catch (BusinessException e){ | 
|---|
|  |  |  | return ApiResponse.failed(e.getCode(),e.getMessage()); | 
|---|
|  |  |  | }catch (Exception e){ | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | return ApiResponse.failed(ResponseStatus.SERVER_ERROR); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PreventRepeat(limit = 10, lockTime = 10000) | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PreventRepeat(limit = 10, lockTime = 10000) | 
|---|
|  |  |  | @ApiOperation("司机登录") | 
|---|
|  |  |  | @PostMapping("/loginDriver") | 
|---|
|  |  |  | @LoginNoRequired | 
|---|
|  |  |  | public ApiResponse<String> loginDriver (@Validated @RequestBody LoginDTO dto, ServerWebExchange serverWebExchange) { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | ServerHttpRequest request = serverWebExchange.getRequest(); | 
|---|
|  |  |  | dto.setCheckCode(false); | 
|---|
|  |  |  | LoginUserInfo user = systemLoginService.driverLogin(dto,request); | 
|---|
|  |  |  | String token = jwtTokenUtil.generateToken(user); | 
|---|
|  |  |  | return ApiResponse.success(token); | 
|---|
|  |  |  | }catch (BusinessException e){ | 
|---|
|  |  |  | return ApiResponse.failed(e.getCode(),e.getMessage()); | 
|---|
|  |  |  | }catch (Exception e){ | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | return ApiResponse.failed(ResponseStatus.SERVER_ERROR); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 刷新JWT令牌,用旧的令牌换新的令牌 | 
|---|
|  |  |  | 
|---|
|  |  |  | }catch (Exception e){ | 
|---|
|  |  |  | return ApiResponse.failed(ResponseStatus.SERVER_ERROR); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 刷新JWT令牌,用旧的令牌换新的令牌 | 
|---|
|  |  |  | 
|---|
|  |  |  | @ApiOperation("退出登陆") | 
|---|
|  |  |  | public ApiResponse<String> logout(@RequestHeader(Constants.HEADER_USER_TOKEN) String oldToken){ | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | jwtTokenUtil.logout(oldToken); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | jwtTokenUtil.logout(oldToken); | 
|---|
|  |  |  | }catch (BusinessException e){ | 
|---|
|  |  |  | return ApiResponse.failed(e.getCode(),e.getMessage()); | 
|---|
|  |  |  | }catch (Exception e){ | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @PostMapping("/logoutForH5") | 
|---|
|  |  |  | @ApiOperation("退出登陆") | 
|---|
|  |  |  | public ApiResponse<String> logoutForH5(@RequestHeader(Constants.HEADER_USER_TOKEN) String oldToken){ | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | jwtTokenUtil.logoutForH5(oldToken); | 
|---|
|  |  |  | }catch (BusinessException e){ | 
|---|
|  |  |  | return ApiResponse.failed(e.getCode(),e.getMessage()); | 
|---|
|  |  |  | }catch (Exception e){ | 
|---|
|  |  |  | return ApiResponse.failed(ResponseStatus.SERVER_ERROR); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return ApiResponse.success(null); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 刷新JWT令牌,用旧的令牌换新的令牌 | 
|---|
|  |  |  | */ | 
|---|