|
@@ -1,10 +1,13 @@
|
|
package com.gyee.runeconomy.controller;
|
|
package com.gyee.runeconomy.controller;
|
|
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
|
+import com.alibaba.fastjson.TypeReference;
|
|
import com.gyee.common.model.StringUtils;
|
|
import com.gyee.common.model.StringUtils;
|
|
import com.gyee.runeconomy.dto.R;
|
|
import com.gyee.runeconomy.dto.R;
|
|
import com.gyee.runeconomy.dto.ResultMsg;
|
|
import com.gyee.runeconomy.dto.ResultMsg;
|
|
import com.gyee.runeconomy.model.vo.TokenVo;
|
|
import com.gyee.runeconomy.model.vo.TokenVo;
|
|
import com.gyee.runeconomy.service.TokenService;
|
|
import com.gyee.runeconomy.service.TokenService;
|
|
|
|
+import com.gyee.runeconomy.util.redis.RedisService;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import org.springframework.stereotype.Controller;
|
|
import org.springframework.stereotype.Controller;
|
|
@@ -15,6 +18,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
|
|
+import java.util.Map;
|
|
|
|
|
|
@Controller
|
|
@Controller
|
|
@RequestMapping("/auth")
|
|
@RequestMapping("/auth")
|
|
@@ -24,17 +28,28 @@ public class AuthController {
|
|
|
|
|
|
@Resource
|
|
@Resource
|
|
private TokenService tokenService;
|
|
private TokenService tokenService;
|
|
-
|
|
|
|
|
|
+ @Resource
|
|
|
|
+ private RedisService redisService;
|
|
@PostMapping("/login")
|
|
@PostMapping("/login")
|
|
@ResponseBody
|
|
@ResponseBody
|
|
@ApiOperation(value = "使用账号密码登录")
|
|
@ApiOperation(value = "使用账号密码登录")
|
|
public R login(@RequestBody TokenVo tokenVo) {
|
|
public R login(@RequestBody TokenVo tokenVo) {
|
|
|
|
|
|
if (StringUtils.notEmp(tokenVo)) {
|
|
if (StringUtils.notEmp(tokenVo)) {
|
|
|
|
+ redisService.select(9);
|
|
|
|
+ if (redisService.hasKey("userSessions")) {
|
|
|
|
+ String cp0String = redisService.get("userSessions");
|
|
|
|
+ tokenService.sessionMap= JSONObject.parseObject(cp0String, new TypeReference<Map<String, TokenVo>>() {
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
|
|
if (!tokenService.sessionMap.containsKey(tokenVo.getToken())) {
|
|
if (!tokenService.sessionMap.containsKey(tokenVo.getToken())) {
|
|
tokenVo.setTime(new Date());
|
|
tokenVo.setTime(new Date());
|
|
tokenService.sessionMap.put(tokenVo.getToken(), tokenVo);
|
|
tokenService.sessionMap.put(tokenVo.getToken(), tokenVo);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ String s = JSONObject.toJSONString(tokenService.sessionMap);
|
|
|
|
+ redisService.set("userSessions",s);
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
@@ -47,11 +62,21 @@ public class AuthController {
|
|
@ResponseBody
|
|
@ResponseBody
|
|
public R logout(@RequestBody TokenVo tokenVo) {
|
|
public R logout(@RequestBody TokenVo tokenVo) {
|
|
if (StringUtils.notEmp(tokenVo) && StringUtils.notEmp(tokenVo.getToken())) {
|
|
if (StringUtils.notEmp(tokenVo) && StringUtils.notEmp(tokenVo.getToken())) {
|
|
|
|
+ redisService.select(9);
|
|
|
|
+ if (redisService.hasKey("userSessions")) {
|
|
|
|
+ String cp0String = redisService.get("userSessions");
|
|
|
|
+ tokenService.sessionMap= JSONObject.parseObject(cp0String, new TypeReference<Map<String, TokenVo>>() {
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
|
|
if (tokenService.sessionMap.containsKey(tokenVo.getToken())) {
|
|
if (tokenService.sessionMap.containsKey(tokenVo.getToken())) {
|
|
tokenService.sessionMap.remove(tokenVo.getToken());
|
|
tokenService.sessionMap.remove(tokenVo.getToken());
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ String s = JSONObject.toJSONString(tokenService.sessionMap);
|
|
|
|
+ redisService.set("userSessions",s);
|
|
|
|
+
|
|
|
|
+
|
|
if (tokenService.sessionWtMap.containsKey(tokenVo.getToken())) {
|
|
if (tokenService.sessionWtMap.containsKey(tokenVo.getToken())) {
|
|
tokenService.sessionWtMap.remove(tokenVo.getToken());
|
|
tokenService.sessionWtMap.remove(tokenVo.getToken());
|
|
}
|
|
}
|