-
Notifications
You must be signed in to change notification settings - Fork 822
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
pcm
committed
Nov 25, 2024
1 parent
ae7602d
commit 9605e6d
Showing
34 changed files
with
2,946 additions
and
129 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
springboot-saToken/src/main/java/com/pancm/config/SaTokenConfigure.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.pancm.config; | ||
|
||
|
||
import cn.dev33.satoken.interceptor.SaRouteInterceptor; | ||
import cn.dev33.satoken.stp.StpUtil; | ||
|
||
import com.pancm.interceptors.PermissionInterceptor; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
|
||
import javax.annotation.Resource; | ||
|
||
/*** | ||
* 登录权限验证 | ||
*/ | ||
@Configuration | ||
public class SaTokenConfigure implements WebMvcConfigurer { | ||
|
||
|
||
@Resource | ||
private PermissionInterceptor permissionInterceptor; | ||
|
||
// 需要排除的路径 | ||
private static final String[] EXCLUDE_PATHS = {"/login/**"}; | ||
|
||
// 注册拦截器 | ||
@Override | ||
public void addInterceptors(InterceptorRegistry registry) { | ||
registerSaTokenInterceptor(registry); | ||
registerPermissionInterceptor(registry); | ||
} | ||
|
||
// 注册 Sa-Token 拦截器 | ||
private void registerSaTokenInterceptor(InterceptorRegistry registry) { | ||
registry.addInterceptor(new SaRouteInterceptor((r, s, o) -> StpUtil.checkLogin())) | ||
.addPathPatterns("/**") | ||
.excludePathPatterns(EXCLUDE_PATHS); | ||
} | ||
|
||
// 注册权限拦截器 | ||
private void registerPermissionInterceptor(InterceptorRegistry registry) { | ||
registry.addInterceptor(permissionInterceptor) | ||
.addPathPatterns("/**") | ||
.excludePathPatterns(EXCLUDE_PATHS); | ||
} | ||
|
||
|
||
|
||
} |
6 changes: 6 additions & 0 deletions
6
springboot-saToken/src/main/java/com/pancm/constant/UserConstants.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.pancm.constant; | ||
|
||
public interface UserConstants { | ||
|
||
String CURRENT_USER = "current_user"; | ||
} |
91 changes: 91 additions & 0 deletions
91
springboot-saToken/src/main/java/com/pancm/controller/LoginController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package com.pancm.controller; | ||
|
||
|
||
import cn.dev33.satoken.stp.StpUtil; | ||
|
||
import com.pancm.constant.UserConstants; | ||
import com.pancm.enums.PcmYesNoEnum; | ||
import com.pancm.service.ISysPermissionService; | ||
import com.pancm.service.ISysUserInfoService; | ||
import com.pancm.service.ISysUserRoleService; | ||
import com.pancm.vo.ApiResult; | ||
import com.pancm.vo.SysPermissionVO; | ||
import com.pancm.vo.SysUserInfoVO; | ||
import com.pancm.vo.SysUserRoleVO; | ||
import io.swagger.annotations.Api; | ||
import io.swagger.annotations.ApiOperation; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import javax.annotation.Resource; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
/** | ||
* <p> | ||
* 用户登录 controller | ||
* </p> | ||
* | ||
* @author pcm | ||
* @menu 用户登录 | ||
* @since 2024-11-20 | ||
*/ | ||
@Api(tags = "REST - 用户登录") | ||
@RestController | ||
@RequestMapping("/login") | ||
public class LoginController { | ||
|
||
@Resource | ||
private ISysUserInfoService sysUserInfoService; | ||
@Resource | ||
private ISysUserRoleService userRoleService; | ||
@Resource | ||
private ISysPermissionService permissionService; | ||
|
||
|
||
@PostMapping("/login") | ||
@ApiOperation(value = "登录", notes = "登录") | ||
public ApiResult login(@RequestParam(value = "username") String username, @RequestParam(value = "password") String password) { | ||
SysUserInfoVO userInfoVO = sysUserInfoService.queryByUserName(username); | ||
if (userInfoVO == null || !Objects.equals(userInfoVO.getPassword(), password)) { | ||
return ApiResult.error("用户名或密码错误!"); | ||
} | ||
if(Objects.equals(userInfoVO.getUserEnable(), PcmYesNoEnum.NO.getIndex())){ | ||
return ApiResult.error("该用户已被禁用!请联系管理员!"); | ||
} | ||
SysUserRoleVO roleDTO = userRoleService.queryById(userInfoVO.getRoleId()); | ||
if(roleDTO == null || Objects.equals(roleDTO.getUserEnable(), PcmYesNoEnum.NO.getIndex())){ | ||
return ApiResult.error("该用户所属角色已被禁用或已删除!请联系管理员!"); | ||
} | ||
List<SysPermissionVO> list = permissionService.queryRolePermissionByRoleId(userInfoVO.getRoleId()); | ||
if(list == null || list.isEmpty()){ | ||
return ApiResult.error("该用户所属角色未配置权限!请联系管理员!"); | ||
} | ||
userInfoVO.setPermissionDTOLists(list); | ||
userInfoVO.setPassword(null); | ||
StpUtil.login(username); | ||
StpUtil.getSession().set(UserConstants.CURRENT_USER, userInfoVO); | ||
return ApiResult.success(userInfoVO); | ||
} | ||
|
||
@ApiOperation(value = "登录校验", notes = "登录校验") | ||
@RequestMapping("/isLogin") | ||
public ApiResult isLogin() { | ||
return ApiResult.success(StpUtil.isLogin()); | ||
} | ||
|
||
@ApiOperation(value = "登出", notes = "登出") | ||
@PostMapping("/logout") | ||
public ApiResult logout() { | ||
StpUtil.getSession().clear(); | ||
StpUtil.logout(); | ||
return ApiResult.success(); | ||
} | ||
|
||
|
||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
springboot-saToken/src/main/java/com/pancm/controller/SysUserInfoController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package com.pancm.controller; | ||
|
||
import com.pancm.vo.SysUserInfoVO; | ||
import com.pancm.service.ISysUserInfoService; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
|
||
import com.pancm.vo.ApiResult; | ||
import io.swagger.annotations.Api; | ||
import io.swagger.annotations.ApiOperation; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestMethod; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
|
||
|
||
|
||
/** | ||
* @Title: 系统用户表(SysUserInfo)表控制层 | ||
* @Description: | ||
* @Version:1.0.0 | ||
* @Since:jdk1.8 | ||
* @author pancm | ||
* @date 2024-11-23 09:31:42 | ||
*/ | ||
@Api(tags = "系统用户表(SysUserInfo)") | ||
@RestController | ||
@RequestMapping("sysUserInfo") | ||
public class SysUserInfoController { | ||
/** | ||
* 服务对象 | ||
*/ | ||
@Autowired | ||
private ISysUserInfoService sysUserInfoService; | ||
|
||
|
||
/** | ||
* 新增一条数据 | ||
* | ||
* @param sysUserInfoVO 实体类 | ||
* @return Response对象 | ||
*/ | ||
@ApiOperation(value = "系统用户表新增",notes = "系统用户表新增") | ||
@RequestMapping(value = "save", method = RequestMethod.POST) | ||
public ApiResult insert(@RequestBody SysUserInfoVO sysUserInfoVO, HttpServletRequest httpRequest) { | ||
int result = sysUserInfoService.insert(sysUserInfoVO); | ||
if (result > 0) { | ||
return ApiResult.success(); | ||
} | ||
return ApiResult.error("新增失败"); | ||
} | ||
|
||
/** | ||
* 修改一条数据 | ||
* | ||
* @param sysUserInfoVO 实体类 | ||
* @return Response对象 | ||
*/ | ||
@ApiOperation(value = "系统用户表修改",notes = "系统用户表修改") | ||
@RequestMapping(value = "edit", method = RequestMethod.POST) | ||
public ApiResult update(@RequestBody SysUserInfoVO sysUserInfoVO, HttpServletRequest httpRequest) { | ||
sysUserInfoService.update(sysUserInfoVO); | ||
return ApiResult.success(); | ||
} | ||
|
||
/** | ||
* 删除一条数据 | ||
* | ||
* @param sysUserInfoVO 参数对象 | ||
* @return Response对象 | ||
*/ | ||
@ApiOperation(value = "系统用户表删除",notes = "系统用户表删除") | ||
@RequestMapping(value = "del", method = RequestMethod.POST) | ||
public ApiResult delete(@RequestBody SysUserInfoVO sysUserInfoVO, HttpServletRequest httpRequest) { | ||
sysUserInfoService.deleteById(sysUserInfoVO.getId()); | ||
return ApiResult.success(); | ||
} | ||
|
||
|
||
|
||
/** | ||
* 分页查询 | ||
* | ||
*/ | ||
@ApiOperation(value = "系统用户表查询",notes = "系统用户表查询") | ||
@RequestMapping(value = "list", method = RequestMethod.POST) | ||
public ApiResult list(@RequestBody SysUserInfoVO sysUserInfoVO) { | ||
return sysUserInfoService.list(sysUserInfoVO); | ||
} | ||
|
||
/** | ||
* 详情查询 | ||
* | ||
*/ | ||
@ApiOperation(value = "系统用户表详情",notes = "系统用户表详情") | ||
@RequestMapping(value = "view", method = RequestMethod.GET) | ||
public ApiResult view( @RequestParam("id") Integer id) { | ||
return ApiResult.success(sysUserInfoService.queryById(id)); | ||
} | ||
} |
Oops, something went wrong.