| | |
| | | import com.oying.modules.security.service.UserDetailsServiceImpl; |
| | | import com.oying.modules.security.service.dto.AuthUserDto; |
| | | import com.oying.modules.security.service.dto.JwtUserDto; |
| | | import com.oying.utils.*; |
| | | import com.wf.captcha.base.Captcha; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | |
| | | import com.oying.annotation.rest.AnonymousPostMapping; |
| | | import com.oying.config.properties.RsaProperties; |
| | | import com.oying.exception.BadRequestException; |
| | | import com.oying.utils.RsaUtils; |
| | | import com.oying.utils.RedisUtils; |
| | | import com.oying.utils.SecurityUtils; |
| | | import com.oying.utils.StringUtils; |
| | | import org.springframework.http.HttpStatus; |
| | | import org.springframework.http.ResponseEntity; |
| | | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; |
| | |
| | | import org.springframework.security.crypto.password.PasswordEncoder; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | |
| | | // 保存在线信息 |
| | | onlineUserService.save(jwtUser, token, request); |
| | | // 返回登录信息 |
| | | return ResponseEntity.ok(authInfo); |
| | | return ResponseEntity.ok(R.success(authInfo)); |
| | | } |
| | | |
| | | @ApiOperation("临时授权") |
| | | @AnonymousPostMapping(value = "/token") |
| | | @AnonymousGetMapping(value = "/token") |
| | | public ResponseEntity<Object> loginTest(@RequestParam String username, HttpServletRequest request) { |
| | | // 生成令牌与第三方系统获取令牌方式 |
| | | JwtUserDto jwtUser = userDetailsService.loadUserByUsername(username); |
| | |
| | | // 保存在线信息 |
| | | onlineUserService.save(jwtUser, token, request); |
| | | // 返回登录信息 |
| | | return ResponseEntity.ok(authInfo); |
| | | return ResponseEntity.ok(R.success(authInfo)); |
| | | } |
| | | |
| | | @ApiOperation("获取用户信息") |
| | | @GetMapping(value = "/info") |
| | | public ResponseEntity<UserDetails> getUserInfo() { |
| | | public ResponseEntity<Object> getUserInfo() { |
| | | JwtUserDto jwtUser = (JwtUserDto) SecurityUtils.getCurrentUser(); |
| | | return ResponseEntity.ok(jwtUser); |
| | | return ResponseEntity.ok(R.success(jwtUser)); |
| | | } |
| | | |
| | | @ApiOperation("获取验证码") |
| | |
| | | put("img", captcha.toBase64()); |
| | | put("uuid", uuid); |
| | | }}; |
| | | return ResponseEntity.ok(imgResult); |
| | | return ResponseEntity.ok(R.success(imgResult)); |
| | | } |
| | | |
| | | @ApiOperation("退出登录") |
| | |
| | | public ResponseEntity<Object> logout(HttpServletRequest request) { |
| | | String token = tokenProvider.getToken(request); |
| | | onlineUserService.logout(token); |
| | | return new ResponseEntity<>(HttpStatus.OK); |
| | | return new ResponseEntity<>(R.success(), HttpStatus.OK); |
| | | } |
| | | } |