|
@@ -1,22 +1,25 @@
|
|
package com.fdkk.sxz.system.controller;
|
|
package com.fdkk.sxz.system.controller;
|
|
|
|
|
|
import cn.hutool.captcha.GifCaptcha;
|
|
import cn.hutool.captcha.GifCaptcha;
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.fdkk.sxz.annotation.auth.CurrentUser;
|
|
import com.fdkk.sxz.annotation.auth.CurrentUser;
|
|
import com.fdkk.sxz.annotation.auth.NoAuthentication;
|
|
import com.fdkk.sxz.annotation.auth.NoAuthentication;
|
|
-import com.fdkk.sxz.system.dto.UserInfo;
|
|
|
|
-import com.fdkk.sxz.entity.system.Resource;
|
|
|
|
-import com.fdkk.sxz.entity.system.Role;
|
|
|
|
|
|
+import com.fdkk.sxz.base.BaseController;
|
|
|
|
+import com.fdkk.sxz.base.Result;
|
|
import com.fdkk.sxz.constant.Constant;
|
|
import com.fdkk.sxz.constant.Constant;
|
|
import com.fdkk.sxz.constant.ResponseConstant;
|
|
import com.fdkk.sxz.constant.ResponseConstant;
|
|
-import com.fdkk.sxz.base.BaseController;
|
|
|
|
-import com.fdkk.sxz.system.dto.LoginUser;
|
|
|
|
|
|
+import com.fdkk.sxz.entity.system.Resource;
|
|
|
|
+import com.fdkk.sxz.entity.system.Role;
|
|
import com.fdkk.sxz.entity.system.User;
|
|
import com.fdkk.sxz.entity.system.User;
|
|
import com.fdkk.sxz.other.shiro.conponent.JwtComponent;
|
|
import com.fdkk.sxz.other.shiro.conponent.JwtComponent;
|
|
|
|
+import com.fdkk.sxz.system.dto.LoginUser;
|
|
|
|
+import com.fdkk.sxz.system.dto.UserInfo;
|
|
import com.fdkk.sxz.system.service.IResourceService;
|
|
import com.fdkk.sxz.system.service.IResourceService;
|
|
import com.fdkk.sxz.system.service.IUserRoleService;
|
|
import com.fdkk.sxz.system.service.IUserRoleService;
|
|
import com.fdkk.sxz.system.service.IUserService;
|
|
import com.fdkk.sxz.system.service.IUserService;
|
|
-import com.fdkk.sxz.base.Result;
|
|
|
|
|
|
+import com.fdkk.sxz.util.RedisUtil;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.ApiImplicitParam;
|
|
import io.swagger.annotations.ApiImplicitParam;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import io.swagger.annotations.ApiOperation;
|
|
@@ -36,11 +39,13 @@ import javax.servlet.http.HttpServletResponse;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Locale;
|
|
import java.util.Locale;
|
|
|
|
+import java.util.Map;
|
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
/**
|
|
/**
|
|
|
|
+ * @author Xiewj
|
|
* @ClassName: LoginController
|
|
* @ClassName: LoginController
|
|
* @Description: 登录相关前端控制器
|
|
* @Description: 登录相关前端控制器
|
|
- * @author Xiewj
|
|
|
|
* @date 2018年5月18日 下午4:08:26
|
|
* @date 2018年5月18日 下午4:08:26
|
|
*/
|
|
*/
|
|
@RestController
|
|
@RestController
|
|
@@ -62,10 +67,17 @@ public class SysLoginController extends BaseController {
|
|
|
|
|
|
// @Autowired
|
|
// @Autowired
|
|
// ISmsService iSmsService;
|
|
// ISmsService iSmsService;
|
|
|
|
+ /**
|
|
|
|
+ * 过期时间
|
|
|
|
+ */
|
|
|
|
+ @Value("#{${system.expireTime}}")
|
|
|
|
+ private Map<String, Long> expireTime;
|
|
|
|
|
|
@Value("${system.smsTimes}")
|
|
@Value("${system.smsTimes}")
|
|
private int smsTimes;
|
|
private int smsTimes;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private RedisUtil redisUtil;
|
|
|
|
|
|
@GetMapping("/vcode")
|
|
@GetMapping("/vcode")
|
|
@NoAuthentication
|
|
@NoAuthentication
|
|
@@ -107,6 +119,8 @@ public class SysLoginController extends BaseController {
|
|
return error(ResponseConstant.INVALID_USERNAME_PASSWORD);
|
|
return error(ResponseConstant.INVALID_USERNAME_PASSWORD);
|
|
}
|
|
}
|
|
String token = jwtComponent.sign(user.getUserAccount(), user.getUserPassword(), Constant.ExpTimeType.WEB);
|
|
String token = jwtComponent.sign(user.getUserAccount(), user.getUserPassword(), Constant.ExpTimeType.WEB);
|
|
|
|
+ long expTime = expireTime.get(Constant.ExpTimeType.WEB);
|
|
|
|
+ redisUtil.setEx("userLoginToken:" + token, JSON.toJSONString(user), expTime, TimeUnit.MILLISECONDS);
|
|
return successPut(token);
|
|
return successPut(token);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -145,10 +159,12 @@ public class SysLoginController extends BaseController {
|
|
@GetMapping("/token/refresh")
|
|
@GetMapping("/token/refresh")
|
|
@RequiresAuthentication
|
|
@RequiresAuthentication
|
|
@ApiOperation(value = "刷新token")
|
|
@ApiOperation(value = "刷新token")
|
|
- public Result<String> refreshToken( @ApiIgnore @CurrentUser User currentUser) {
|
|
|
|
|
|
+ public Result<String> refreshToken(@ApiIgnore @CurrentUser User currentUser) {
|
|
Long userId = currentUser.getId();
|
|
Long userId = currentUser.getId();
|
|
User user = userService.getById(userId);
|
|
User user = userService.getById(userId);
|
|
String token = jwtComponent.sign(user.getUserAccount(), user.getUserPassword(), Constant.ExpTimeType.WEB);
|
|
String token = jwtComponent.sign(user.getUserAccount(), user.getUserPassword(), Constant.ExpTimeType.WEB);
|
|
|
|
+ long expTime = expireTime.get(Constant.ExpTimeType.WEB);
|
|
|
|
+ redisUtil.setEx("userLoginToken:" + token, JSON.toJSONString(user), expTime, TimeUnit.MILLISECONDS);
|
|
return successPut(token);
|
|
return successPut(token);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -440,7 +456,10 @@ public class SysLoginController extends BaseController {
|
|
@PostMapping("/logout")
|
|
@PostMapping("/logout")
|
|
@NoAuthentication
|
|
@NoAuthentication
|
|
@ApiOperation(value = "退出登录")
|
|
@ApiOperation(value = "退出登录")
|
|
- public Result<?> logOut(HttpServletRequest request) throws Exception {
|
|
|
|
|
|
+ public Result<?> logOut(@RequestBody JSONObject json) throws Exception {
|
|
|
|
+ if (json.containsKey("keys")) {
|
|
|
|
+ redisUtil.delete("userLoginToken:" + json.get("keys"));
|
|
|
|
+ }
|
|
return success();
|
|
return success();
|
|
}
|
|
}
|
|
|
|
|