|
|
@@ -20,6 +20,7 @@ import org.springframework.web.bind.annotation.RestController;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.xintong.visualinspection.bean.User;
|
|
|
import com.xintong.visualinspection.pojo.JwtAuthenticationResponse;
|
|
|
+import com.xintong.visualinspection.securityTools.RedisCacheUtil;
|
|
|
import com.xintong.visualinspection.service.AuthService;
|
|
|
import com.xintong.visualinspection.service.UserService;
|
|
|
|
|
|
@@ -37,14 +38,31 @@ public class UserController extends BaseController {
|
|
|
@Autowired
|
|
|
private AuthService authService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private RedisCacheUtil redisCacheUtil;
|
|
|
+
|
|
|
@Value("${jwt.header}")
|
|
|
private String tokenHeader;
|
|
|
|
|
|
@RequestMapping(value = "/auth/login",method=RequestMethod.POST)
|
|
|
- public User login(@RequestBody User user){
|
|
|
+ public String login(@RequestBody User user){
|
|
|
User u = authService.login(user.getUsername(), user.getPassword());
|
|
|
- return u;
|
|
|
+ return returnSuccessResult("登陆成功", u);
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping(value = "/logout",method=RequestMethod.POST)
|
|
|
+ public String logout(){
|
|
|
+ //获取用户名
|
|
|
+ String username = SecurityContextHolder.getContext().getAuthentication().getName();
|
|
|
+ if(username!=null){
|
|
|
+ redisCacheUtil.removeForUserName(username);
|
|
|
+ }
|
|
|
+ //返回参数
|
|
|
+ return returnSuccessResult("退出成功");
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 添加用户
|
|
|
* @return
|