From 0b077806196ceb8a68af93f00880ccc70aee50c2 Mon Sep 17 00:00:00 2001 From: 疯狂的狮子li <15040126243@163.com> Date: 星期四, 07 七月 2022 18:08:14 +0800 Subject: [PATCH] add 整合 springdoc 移除 knife4j --- ruoyi-system/src/main/java/com/ruoyi/system/service/SysLoginService.java | 23 ++++++++++++++++------- 1 files changed, 16 insertions(+), 7 deletions(-) diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/SysLoginService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/SysLoginService.java index 440bca5..5a43203 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/SysLoginService.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/SysLoginService.java @@ -1,9 +1,11 @@ package com.ruoyi.system.service; +import cn.dev33.satoken.exception.NotLoginException; import cn.dev33.satoken.secure.BCrypt; import cn.dev33.satoken.stp.StpUtil; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.util.ObjectUtil; +import com.ruoyi.common.constant.CacheConstants; import com.ruoyi.common.constant.Constants; import com.ruoyi.common.core.domain.dto.RoleDTO; import com.ruoyi.common.core.domain.entity.SysUser; @@ -113,16 +115,23 @@ return StpUtil.getTokenValue(); } - - public void logout(String loginName) { - asyncService.recordLogininfor(loginName, Constants.LOGOUT, MessageUtils.message("user.logout.success"), ServletUtils.getRequest()); + /** + * 閫�鍑虹櫥褰� + */ + public void logout() { + try { + String username = LoginHelper.getUsername(); + StpUtil.logout(); + asyncService.recordLogininfor(username, Constants.LOGOUT, MessageUtils.message("user.logout.success"), ServletUtils.getRequest()); + } catch (NotLoginException e) { + } } /** * 鏍¢獙鐭俊楠岃瘉鐮� */ private boolean validateSmsCode(String phonenumber, String smsCode, HttpServletRequest request) { - String code = RedisUtils.getCacheObject(Constants.CAPTCHA_CODE_KEY + phonenumber); + String code = RedisUtils.getCacheObject(CacheConstants.CAPTCHA_CODE_KEY + phonenumber); if (StringUtils.isBlank(code)) { asyncService.recordLogininfor(phonenumber, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.expire"), request); throw new CaptchaExpireException(); @@ -138,7 +147,7 @@ * @param uuid 鍞竴鏍囪瘑 */ public void validateCaptcha(String username, String code, String uuid, HttpServletRequest request) { - String verifyKey = Constants.CAPTCHA_CODE_KEY + StringUtils.defaultString(uuid, ""); + String verifyKey = CacheConstants.CAPTCHA_CODE_KEY + StringUtils.defaultString(uuid, ""); String captcha = RedisUtils.getCacheObject(verifyKey); RedisUtils.deleteObject(verifyKey); if (captcha == null) { @@ -209,7 +218,7 @@ loginUser.setUserType(user.getUserType()); loginUser.setMenuPermission(permissionService.getMenuPermission(user)); loginUser.setRolePermission(permissionService.getRolePermission(user)); - loginUser.setDeptName(user.getDept().getDeptName()); + loginUser.setDeptName(ObjectUtil.isNull(user.getDept()) ? "" : user.getDept().getDeptName()); List<RoleDTO> roles = BeanUtil.copyToList(user.getRoles(), RoleDTO.class); loginUser.setRoles(roles); return loginUser; @@ -234,7 +243,7 @@ */ private void checkLogin(LoginType loginType, String username, Supplier<Boolean> supplier) { HttpServletRequest request = ServletUtils.getRequest(); - String errorKey = Constants.LOGIN_ERROR + username; + String errorKey = CacheConstants.LOGIN_ERROR + username; Integer errorLimitTime = Constants.LOGIN_ERROR_LIMIT_TIME; Integer setErrorNumber = Constants.LOGIN_ERROR_NUMBER; String loginFail = Constants.LOGIN_FAIL; -- Gitblit v1.9.3