Skip to content

Commit

Permalink
pro-front整理完毕
Browse files Browse the repository at this point in the history
  • Loading branch information
deepraining committed Sep 6, 2022
1 parent 9a29bf1 commit c6c658f
Show file tree
Hide file tree
Showing 117 changed files with 1,244 additions and 2,387 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@

- `pro-common`: 通用代码
- `pro-mbg`: Mybatis Generator
- `pro-demo`: 使用 Session-Cookie 保持登陆状态的 Demo 应用
- `pro-jwtdemo`: 使用 JWT 保持登陆状态的 Demo 应用,示例前端项目 [sbs-jwtdemo-web](https://github.com/deepraining/sbs-jwtdemo-web)
- `pro-admin`: 使用 JWT 保持登陆状态的后台管理应用,包括基于角色的访问控制(RBAC),示例前端项目 [sbs-admin-web](https://github.com/deepraining/sbs-admin-web)
- `pro-front`: 使用 Session-Cookie 保持登陆状态的前端应用

## 扩展 Gradle Tasks

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public CommonResult<AdminUser> register(
@ApiOperation(value = "登录以后返回token")
@RequestMapping(value = "/login", method = RequestMethod.POST)
@ResponseBody
public CommonResult login(
public CommonResult<Map<String, String>> login(
@RequestBody @Validated AdminLoginParam adminLoginParam, BindingResult bindingResult) {
String token = userService.login(adminLoginParam.getUsername(), adminLoginParam.getPassword());
if (token == null) {
Expand All @@ -70,7 +70,7 @@ public CommonResult login(
@ApiOperation(value = "刷新token")
@RequestMapping(value = "/refreshToken", method = RequestMethod.GET)
@ResponseBody
public CommonResult refreshToken(HttpServletRequest request) {
public CommonResult<Map<String, String>> refreshToken(HttpServletRequest request) {
String token = request.getHeader(tokenHeader);
String refreshToken = userService.refreshToken(token);
if (refreshToken == null) {
Expand All @@ -85,9 +85,9 @@ public CommonResult refreshToken(HttpServletRequest request) {
@ApiOperation(value = "获取当前登录用户信息")
@RequestMapping(value = "/info", method = RequestMethod.GET)
@ResponseBody
public CommonResult getAdminInfo(Principal principal) {
public CommonResult<Map<String, Object>> getAdminInfo(Principal principal) {
if (principal == null) {
return CommonResult.unauthorized(null);
return CommonResult.unauthorized();
}
String username = principal.getName();
AdminUser adminUser = userService.getUserByUsername(username);
Expand All @@ -103,7 +103,7 @@ public CommonResult getAdminInfo(Principal principal) {
@ApiOperation(value = "登出功能")
@RequestMapping(value = "/logout", method = RequestMethod.POST)
@ResponseBody
public CommonResult logout() {
public CommonResult<Object> logout() {
return CommonResult.success(null);
}

Expand All @@ -129,7 +129,7 @@ public CommonResult<AdminUser> getItem(@PathVariable Long id) {
@ApiOperation("修改指定用户信息")
@RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
@ResponseBody
public CommonResult update(
public CommonResult<Integer> update(
@PathVariable Long id,
@RequestBody @Validated AdminUser adminUser,
BindingResult bindingResult) {
Expand All @@ -143,7 +143,7 @@ public CommonResult update(
@ApiOperation("修改指定用户密码")
@RequestMapping(value = "/updatePassword", method = RequestMethod.POST)
@ResponseBody
public CommonResult updatePassword(
public CommonResult<Integer> updatePassword(
@RequestBody @Validated AdminUpdatePasswordParam updatePasswordParam,
BindingResult bindingResult) {
int status = userService.updatePassword(updatePasswordParam);
Expand All @@ -163,7 +163,7 @@ public CommonResult updatePassword(
@ApiOperation("删除指定用户信息")
@RequestMapping(value = "/delete/{id}", method = RequestMethod.POST)
@ResponseBody
public CommonResult delete(@PathVariable Long id) {
public CommonResult<Integer> delete(@PathVariable Long id) {
int count = userService.delete(id);
if (count > 0) {
return CommonResult.success(count);
Expand All @@ -174,7 +174,7 @@ public CommonResult delete(@PathVariable Long id) {
@ApiOperation("修改帐号状态")
@RequestMapping(value = "/updateStatus/{id}", method = RequestMethod.POST)
@ResponseBody
public CommonResult updateStatus(
public CommonResult<Integer> updateStatus(
@PathVariable Long id, @RequestParam(value = "status") Integer status) {
AdminUser adminUser = new AdminUser();
adminUser.setStatus(status);
Expand All @@ -188,7 +188,7 @@ public CommonResult updateStatus(
@ApiOperation("给用户分配角色")
@RequestMapping(value = "/role/update", method = RequestMethod.POST)
@ResponseBody
public CommonResult updateRole(
public CommonResult<Integer> updateRole(
@RequestParam("userId") Long userId, @RequestParam("roleIds") List<Long> roleIds) {
int count = userService.updateRole(userId, roleIds);
if (count >= 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class AdminMenuController {
@ApiOperation("添加后台菜单")
@RequestMapping(value = "/create", method = RequestMethod.POST)
@ResponseBody
public CommonResult create(
public CommonResult<Integer> create(
@RequestBody @Validated AdminMenu adminMenu, BindingResult bindingResult) {
int count = menuService.create(adminMenu);
if (count > 0) {
Expand All @@ -42,7 +42,7 @@ public CommonResult create(
@ApiOperation("修改后台菜单")
@RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
@ResponseBody
public CommonResult update(
public CommonResult<Integer> update(
@PathVariable Long id,
@RequestBody @Validated AdminMenu adminMenu,
BindingResult bindingResult) {
Expand All @@ -65,7 +65,7 @@ public CommonResult<AdminMenu> getItem(@PathVariable Long id) {
@ApiOperation("根据ID删除后台菜单")
@RequestMapping(value = "/delete/{id}", method = RequestMethod.POST)
@ResponseBody
public CommonResult delete(@PathVariable Long id) {
public CommonResult<Integer> delete(@PathVariable Long id) {
int count = menuService.delete(id);
if (count > 0) {
return CommonResult.success(count);
Expand Down Expand Up @@ -96,7 +96,8 @@ public CommonResult<List<AdminMenuNode>> treeList() {
@ApiOperation("修改菜单显示状态")
@RequestMapping(value = "/updateHidden/{id}", method = RequestMethod.POST)
@ResponseBody
public CommonResult updateHidden(@PathVariable Long id, @RequestParam("hidden") Integer hidden) {
public CommonResult<Integer> updateHidden(
@PathVariable Long id, @RequestParam("hidden") Integer hidden) {
int count = menuService.updateHidden(id, hidden);
if (count > 0) {
return CommonResult.success(count);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public CommonResult<List<AdminResourceCategory>> listAll() {
@ApiOperation("添加后台资源分类")
@RequestMapping(value = "/create", method = RequestMethod.POST)
@ResponseBody
public CommonResult create(
public CommonResult<Integer> create(
@RequestBody @Validated AdminResourceCategory adminResourceCategory,
BindingResult bindingResult) {
int count = resourceCategoryService.create(adminResourceCategory);
Expand All @@ -48,7 +48,7 @@ public CommonResult create(
@ApiOperation("修改后台资源分类")
@RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
@ResponseBody
public CommonResult update(
public CommonResult<Integer> update(
@PathVariable Long id,
@RequestBody @Validated AdminResourceCategory adminResourceCategory,
BindingResult bindingResult) {
Expand All @@ -63,7 +63,7 @@ public CommonResult update(
@ApiOperation("根据ID删除后台资源")
@RequestMapping(value = "/delete/{id}", method = RequestMethod.POST)
@ResponseBody
public CommonResult delete(@PathVariable Long id) {
public CommonResult<Integer> delete(@PathVariable Long id) {
int count = resourceCategoryService.delete(id);
if (count > 0) {
return CommonResult.success(count);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class AdminResourceController {
@ApiOperation("添加后台资源")
@RequestMapping(value = "/create", method = RequestMethod.POST)
@ResponseBody
public CommonResult create(
public CommonResult<Integer> create(
@RequestBody @Validated AdminResource adminResource, BindingResult bindingResult) {
int count = resourceService.create(adminResource);
dynamicSecurityMetadataSource.clearDataSource();
Expand All @@ -44,7 +44,7 @@ public CommonResult create(
@ApiOperation("修改后台资源")
@RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
@ResponseBody
public CommonResult update(
public CommonResult<Integer> update(
@PathVariable Long id,
@RequestBody @Validated AdminResource adminResource,
BindingResult bindingResult) {
Expand All @@ -68,7 +68,7 @@ public CommonResult<AdminResource> getItem(@PathVariable Long id) {
@ApiOperation("根据ID删除后台资源")
@RequestMapping(value = "/delete/{id}", method = RequestMethod.POST)
@ResponseBody
public CommonResult delete(@PathVariable Long id) {
public CommonResult<Integer> delete(@PathVariable Long id) {
int count = resourceService.delete(id);
dynamicSecurityMetadataSource.clearDataSource();
if (count > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public class AdminRoleController {
@ApiOperation("添加角色")
@RequestMapping(value = "/create", method = RequestMethod.POST)
@ResponseBody
public CommonResult create(@RequestBody @Validated AdminRole role, BindingResult bindingResult) {
public CommonResult<Integer> create(
@RequestBody @Validated AdminRole role, BindingResult bindingResult) {
int count = roleService.create(role);
if (count > 0) {
return CommonResult.success(count);
Expand All @@ -41,7 +42,7 @@ public CommonResult create(@RequestBody @Validated AdminRole role, BindingResult
@ApiOperation("修改角色")
@RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
@ResponseBody
public CommonResult update(
public CommonResult<Integer> update(
@PathVariable Long id, @RequestBody @Validated AdminRole role, BindingResult bindingResult) {
int count = roleService.update(id, role);
if (count > 0) {
Expand All @@ -53,7 +54,7 @@ public CommonResult update(
@ApiOperation("批量删除角色")
@RequestMapping(value = "/delete", method = RequestMethod.POST)
@ResponseBody
public CommonResult delete(@RequestParam("ids") List<Long> ids) {
public CommonResult<Integer> delete(@RequestParam("ids") List<Long> ids) {
int count = roleService.delete(ids);
if (count > 0) {
return CommonResult.success(count);
Expand Down Expand Up @@ -83,7 +84,7 @@ public CommonResult<CommonPage<AdminRole>> list(
@ApiOperation("修改角色状态")
@RequestMapping(value = "/updateStatus/{id}", method = RequestMethod.POST)
@ResponseBody
public CommonResult updateStatus(
public CommonResult<Integer> updateStatus(
@PathVariable Long id, @RequestParam(value = "status") Integer status) {
AdminRole adminRole = new AdminRole();
adminRole.setStatus(status);
Expand Down Expand Up @@ -113,15 +114,16 @@ public CommonResult<List<AdminResource>> listResource(@PathVariable Long roleId)
@ApiOperation("给角色分配菜单")
@RequestMapping(value = "/allocMenu", method = RequestMethod.POST)
@ResponseBody
public CommonResult allocMenu(@RequestParam Long roleId, @RequestParam List<Long> menuIds) {
public CommonResult<Integer> allocMenu(
@RequestParam Long roleId, @RequestParam List<Long> menuIds) {
int count = roleService.allocMenu(roleId, menuIds);
return CommonResult.success(count);
}

@ApiOperation("给角色分配资源")
@RequestMapping(value = "/allocResource", method = RequestMethod.POST)
@ResponseBody
public CommonResult allocResource(
public CommonResult<Integer> allocResource(
@RequestParam Long roleId, @RequestParam List<Long> resourceIds) {
int count = roleService.allocResource(roleId, resourceIds);
return CommonResult.success(count);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public CommonResult<CommonPage<ArticleRecord>> list(
@ApiOperation("添加文章")
@RequestMapping(value = "/create", method = RequestMethod.POST)
@ResponseBody
public CommonResult create(
public CommonResult<Integer> create(
@RequestBody @Validated ArticleCreateParam articleCreateParam, BindingResult bindingResult) {
int count = articleService.create(articleCreateParam);
if (count > 0) {
Expand All @@ -60,7 +60,7 @@ public CommonResult create(
@ApiOperation("修改文章")
@RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
@ResponseBody
public CommonResult update(
public CommonResult<Integer> update(
@PathVariable Long id,
@RequestBody @Validated ArticleCreateParam articleCreateParam,
BindingResult bindingResult) {
Expand All @@ -75,7 +75,7 @@ public CommonResult update(
@ApiOperation("根据ID删除文章")
@RequestMapping(value = "/delete/{id}", method = RequestMethod.POST)
@ResponseBody
public CommonResult delete(@PathVariable Long id) {
public CommonResult<Integer> delete(@PathVariable Long id) {
int count = articleService.delete(id);
if (count > 0) {
return CommonResult.success(count);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public CommonResult<CommonPage<FrontUser>> list(
@ApiOperation("添加前端用户")
@RequestMapping(value = "/create", method = RequestMethod.POST)
@ResponseBody
public CommonResult create(
public CommonResult<Integer> create(
@RequestBody @Validated FrontUserCreateParam frontUserCreateParam,
BindingResult bindingResult) {
int count = frontUserService.create(frontUserCreateParam);
Expand All @@ -61,7 +61,7 @@ public CommonResult create(
@ApiOperation("修改前端用户")
@RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
@ResponseBody
public CommonResult update(
public CommonResult<Integer> update(
@PathVariable Long id,
@RequestBody @Validated FrontUserCreateParam frontUserCreateParam,
BindingResult bindingResult) {
Expand All @@ -76,7 +76,7 @@ public CommonResult update(
@ApiOperation("根据ID删除前端用户")
@RequestMapping(value = "/delete/{id}", method = RequestMethod.POST)
@ResponseBody
public CommonResult delete(@PathVariable Long id) {
public CommonResult<Integer> delete(@PathVariable Long id) {
int count = frontUserService.delete(id);
if (count > 0) {
return CommonResult.success(count);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import lombok.Getter;
import lombok.Setter;

/** 文章创建参数 */
/** 前端用户创建参数 */
@Getter
@Setter
public class FrontUserCreateParam {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ public interface AdminUserService {
/** 根据用户名获取后台管理员 */
AdminUser getUserByUsername(String username);

/** 缓存序列化后会没有password */
AdminUser getUserByUsernameRaw(String username);

/** 注册功能 */
AdminUser register(AdminUserParam adminUserParam);

Expand Down Expand Up @@ -64,4 +67,7 @@ public interface AdminUserService {

/** 获取用户信息 */
UserDetails loadUserDetailsByUsername(String username);

/** 缓存序列化后会没有password */
UserDetails loadUserDetailsByUsernameRaw(String username);
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,20 @@ public AdminUser getUserByUsername(String username) {
return null;
}

@Override
public AdminUser getUserByUsernameRaw(String username) {
AdminUserExample example = new AdminUserExample();
example.createCriteria().andUsernameEqualTo(username);
List<AdminUser> adminList = userMapper.selectByExample(example);
if (adminList != null && adminList.size() > 0) {
AdminUser adminUser = adminList.get(0);
if (adminUser.getStatus() == 1) {
return adminUser;
}
}
return null;
}

@Override
public AdminUser register(AdminUserParam adminUserParam) {
AdminUser adminUser = new AdminUser();
Expand All @@ -94,7 +108,7 @@ public String login(String username, String password) {
String token = null;
// 密码需要客户端加密后传递
try {
UserDetails userDetails = loadUserDetailsByUsername(username);
UserDetails userDetails = loadUserDetailsByUsernameRaw(username);
if (!passwordEncoder.matches(password, userDetails.getPassword())) {
throw new BadCredentialsException("密码不正确");
}
Expand Down Expand Up @@ -266,4 +280,15 @@ public UserDetails loadUserDetailsByUsername(String username) {
}
throw new UsernameNotFoundException("用户名或密码错误");
}

@Override
public UserDetails loadUserDetailsByUsernameRaw(String username) {
// 获取用户信息
AdminUser adminUser = getUserByUsernameRaw(username);
if (adminUser != null) {
List<AdminResource> resourceList = getResourceList(adminUser.getId());
return new AdminUserDetails(adminUser, resourceList);
}
throw new UsernameNotFoundException("用户名或密码错误");
}
}
Loading

0 comments on commit c6c658f

Please sign in to comment.