From 4a23a696f421331990974d30f69d95700aeb9fe4 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Wed, 6 Oct 2021 09:33:21 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E4=BF=AE=E5=A4=8D=E2=80=9C=E7=99=BB?= =?UTF-8?q?=E9=99=86=E2=80=9D=3D=E3=80=8B=E2=80=9C=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E2=80=9D=202.=20=E5=A2=9E=E5=8A=A0=E7=A4=BE=E4=BA=A4=E5=B9=B3?= =?UTF-8?q?=E5=8F=B0=E7=9A=84=E7=BB=91=E5=AE=9A=E4=B8=8E=E8=A7=A3=E7=BB=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 +- sql/ruoyi-vue-pro.sql | 18 ++--- .../controller/auth/SysAuthController.java | 34 +++++--- .../auth/vo/auth/SysAuthLoginReqVO.java | 4 +- .../auth/vo/auth/SysAuthLoginRespVO.java | 2 +- .../auth/vo/auth/SysAuthMenuRespVO.java | 2 +- .../vo/auth/SysAuthPermissionInfoRespVO.java | 2 +- .../auth/vo/auth/SysAuthSocialBindReqVO.java | 35 +++++++++ .../vo/auth/SysAuthSocialLogin2ReqVO.java | 4 +- .../auth/vo/auth/SysAuthSocialLoginReqVO.java | 2 +- .../vo/auth/SysAuthSocialUnbindReqVO.java | 31 ++++++++ .../session/SysUserSessionPageItemRespVO.java | 2 +- .../logger/SysLoginLogController.java | 8 +- .../logger/vo/loginlog/SysLoginLogBaseVO.java | 6 +- .../vo/loginlog/SysLoginLogCreateReqVO.java | 4 +- .../vo/loginlog/SysLoginLogExcelVO.java | 8 +- .../vo/loginlog/SysLoginLogExportReqVO.java | 2 +- .../vo/loginlog/SysLoginLogPageReqVO.java | 2 +- .../logger/vo/loginlog/SysLoginLogRespVO.java | 4 +- .../user/SysUserProfileController.http | 3 + .../user/SysUserProfileController.java | 7 ++ .../user/vo/profile/SysUserProfileRespVO.java | 18 ++++- .../user/vo/user/SysUserRespVO.java | 2 +- .../system/convert/user/SysUserConvert.java | 3 + .../dal/dataobject/logger/SysLoginLogDO.java | 6 +- .../dal/mysql/social/SysSocialUserMapper.java | 4 + .../dal/redis/SysRedisKeyConstants.java | 2 +- .../system/enums/SysDictTypeConstants.java | 4 +- .../system/enums/SysErrorCodeConstants.java | 4 +- .../enums/logger/SysLoginLogTypeEnum.java | 6 +- .../enums/logger/SysLoginResultEnum.java | 2 +- .../system/service/auth/SysAuthService.java | 34 ++++---- .../service/auth/SysUserSessionService.java | 4 +- .../service/auth/impl/SysAuthServiceImpl.java | 40 ++++++---- .../service/logger/SysLoginLogService.java | 12 +-- .../logger/impl/SysLoginLogServiceImpl.java | 2 +- .../impl/SysPermissionServiceImpl.java | 4 +- .../service/social/SysSocialService.java | 18 +++++ .../social/impl/SysSocialServiceImpl.java | 77 +++++++++++++------ .../sms/SysSmsServiceIntegrationTest.java | 2 +- .../service/auth/SysAuthServiceImplTest.java | 2 +- yudao-admin-ui/src/api/login.js | 10 +-- yudao-admin-ui/src/store/modules/user.js | 4 +- yudao-admin-ui/src/views/index_old.vue | 2 +- yudao-admin-ui/src/views/login.vue | 6 +- yudao-admin-ui/src/views/socialLogin.vue | 4 +- .../src/views/system/loginlog/index.vue | 2 +- .../src/views/system/session/index.vue | 2 +- .../YudaoSecurityAutoConfiguration.java | 2 +- .../YudaoWebSecurityConfigurerAdapter.java | 2 +- .../framework/security/core/LoginUser.java | 2 +- .../core/annotations/PreAuthenticated.java | 4 +- .../filter/JwtAuthenticationTokenFilter.java | 2 +- .../core/util/SecurityFrameworkUtils.java | 2 +- .../framework/web/core/filter/DemoFilter.java | 2 +- .../infra/service/auth/SysAuthService.java | 2 +- 56 files changed, 329 insertions(+), 149 deletions(-) create mode 100644 yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/auth/vo/auth/SysAuthSocialBindReqVO.java create mode 100644 yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/auth/vo/auth/SysAuthSocialUnbindReqVO.java create mode 100644 yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/user/SysUserProfileController.http diff --git a/README.md b/README.md index 8e7f558cb..f2251a3e8 100644 --- a/README.md +++ b/README.md @@ -127,11 +127,11 @@ | 模块 | biu | biu | biu | | --- | --- | --- | --- | -| 登陆 & 首页 | ![登录](https://static.iocoder.cn/images/ruoyi-vue-pro/登录.jpg) | ![首页](https://static.iocoder.cn/images/ruoyi-vue-pro/首页.jpg) | ![个人中心](https://static.iocoder.cn/images/ruoyi-vue-pro/个人中心.jpg) | +| 登录 & 首页 | ![登录](https://static.iocoder.cn/images/ruoyi-vue-pro/登录.jpg) | ![首页](https://static.iocoder.cn/images/ruoyi-vue-pro/首页.jpg) | ![个人中心](https://static.iocoder.cn/images/ruoyi-vue-pro/个人中心.jpg) | | 用户 | ![用户管理](https://static.iocoder.cn/images/ruoyi-vue-pro/用户管理.jpg) | ![在线用户](https://static.iocoder.cn/images/ruoyi-vue-pro/在线用户.jpg) | - | | 部门 & 岗位 | ![部门管理](https://static.iocoder.cn/images/ruoyi-vue-pro/部门管理.jpg) | ![岗位管理](https://static.iocoder.cn/images/ruoyi-vue-pro/岗位管理.jpg) | - | | 菜单 & 角色 | ![菜单管理](https://static.iocoder.cn/images/ruoyi-vue-pro/菜单管理.jpg) | ![角色管理](https://static.iocoder.cn/images/ruoyi-vue-pro/角色管理.jpg) | - | -| 审计日志 | ![操作日志](https://static.iocoder.cn/images/ruoyi-vue-pro/操作日志.jpg) | ![登陆日志](https://static.iocoder.cn/images/ruoyi-vue-pro/登陆日志.jpg) | - | +| 审计日志 | ![操作日志](https://static.iocoder.cn/images/ruoyi-vue-pro/操作日志.jpg) | ![登录日志](https://static.iocoder.cn/images/ruoyi-vue-pro/登录日志.jpg) | - | | 短信 | ![短信渠道](https://static.iocoder.cn/images/ruoyi-vue-pro/短信渠道.jpg) | ![短信模板](https://static.iocoder.cn/images/ruoyi-vue-pro/短信模板.jpg) | ![短信日志](https://static.iocoder.cn/images/ruoyi-vue-pro/短信日志.jpg) | | 字典 | ![字典类型](https://static.iocoder.cn/images/ruoyi-vue-pro/字典类型.jpg) | ![字典数据](https://static.iocoder.cn/images/ruoyi-vue-pro/字典数据.jpg) | - | | 错误码 & 通知 | ![错误码管理](https://static.iocoder.cn/images/ruoyi-vue-pro/错误码管理.jpg) | ![通知公告](https://static.iocoder.cn/images/ruoyi-vue-pro/通知公告.jpg) | - | diff --git a/sql/ruoyi-vue-pro.sql b/sql/ruoyi-vue-pro.sql index bfdb2a139..5c8db24a2 100644 --- a/sql/ruoyi-vue-pro.sql +++ b/sql/ruoyi-vue-pro.sql @@ -299,12 +299,12 @@ INSERT INTO `sys_dict_data` VALUES (35, 2, '指定部门数据权限', '2', 'sys INSERT INTO `sys_dict_data` VALUES (36, 3, '本部门数据权限', '3', 'sys_data_scope', 0, '本部门数据权限', 'admin', '2021-01-05 17:03:48', '', '2021-01-06 19:38:29', b'0'); INSERT INTO `sys_dict_data` VALUES (37, 4, '本部门及以下数据权限', '4', 'sys_data_scope', 0, '本部门及以下数据权限', 'admin', '2021-01-05 17:03:48', '', '2021-01-06 19:38:32', b'0'); INSERT INTO `sys_dict_data` VALUES (38, 5, '仅本人数据权限', '5', 'sys_data_scope', 0, '仅本人数据权限', 'admin', '2021-01-05 17:03:48', '', '2021-01-06 19:38:38', b'0'); -INSERT INTO `sys_dict_data` VALUES (39, 0, '成功', '0', 'sys_login_result', 0, '登陆结果 - 成功', '', '2021-01-18 06:17:36', '', '2021-01-18 06:17:36', b'0'); -INSERT INTO `sys_dict_data` VALUES (40, 10, '账号或密码不正确', '10', 'sys_login_result', 0, '登陆结果 - 账号或密码不正确', '', '2021-01-18 06:17:54', '', '2021-01-18 06:17:54', b'0'); -INSERT INTO `sys_dict_data` VALUES (41, 20, '用户被禁用', '20', 'sys_login_result', 0, '登陆结果 - 用户被禁用', '', '2021-01-18 06:17:54', '', '2021-01-18 06:19:02', b'0'); -INSERT INTO `sys_dict_data` VALUES (42, 30, '验证码不存在', '30', 'sys_login_result', 0, '登陆结果 - 验证码不存在', '', '2021-01-18 06:17:54', '', '2021-01-18 06:19:24', b'0'); -INSERT INTO `sys_dict_data` VALUES (43, 31, '验证码不正确', '31', 'sys_login_result', 0, '登陆结果 - 验证码不正确', '', '2021-01-18 06:17:54', '', '2021-01-18 06:19:33', b'0'); -INSERT INTO `sys_dict_data` VALUES (44, 100, '未知异常', '100', 'sys_login_result', 0, '登陆结果 - 未知异常', '', '2021-01-18 06:17:54', '', '2021-01-18 06:19:57', b'0'); +INSERT INTO `sys_dict_data` VALUES (39, 0, '成功', '0', 'sys_login_result', 0, '登录结果 - 成功', '', '2021-01-18 06:17:36', '', '2021-01-18 06:17:36', b'0'); +INSERT INTO `sys_dict_data` VALUES (40, 10, '账号或密码不正确', '10', 'sys_login_result', 0, '登录结果 - 账号或密码不正确', '', '2021-01-18 06:17:54', '', '2021-01-18 06:17:54', b'0'); +INSERT INTO `sys_dict_data` VALUES (41, 20, '用户被禁用', '20', 'sys_login_result', 0, '登录结果 - 用户被禁用', '', '2021-01-18 06:17:54', '', '2021-01-18 06:19:02', b'0'); +INSERT INTO `sys_dict_data` VALUES (42, 30, '验证码不存在', '30', 'sys_login_result', 0, '登录结果 - 验证码不存在', '', '2021-01-18 06:17:54', '', '2021-01-18 06:19:24', b'0'); +INSERT INTO `sys_dict_data` VALUES (43, 31, '验证码不正确', '31', 'sys_login_result', 0, '登录结果 - 验证码不正确', '', '2021-01-18 06:17:54', '', '2021-01-18 06:19:33', b'0'); +INSERT INTO `sys_dict_data` VALUES (44, 100, '未知异常', '100', 'sys_login_result', 0, '登录结果 - 未知异常', '', '2021-01-18 06:17:54', '', '2021-01-18 06:19:57', b'0'); INSERT INTO `sys_dict_data` VALUES (45, 1, '是', 'true', 'sys_boolean_string', 0, 'Boolean 是否类型 - 是', '', '2021-01-19 03:20:55', '', '2021-01-19 03:21:08', b'0'); INSERT INTO `sys_dict_data` VALUES (46, 1, '否', 'false', 'sys_boolean_string', 0, 'Boolean 是否类型 - 否', '', '2021-01-19 03:20:55', '', '2021-01-19 03:21:39', b'0'); INSERT INTO `sys_dict_data` VALUES (47, 1, '永不超时', '1', 'inf_redis_timeout_type', 0, 'Redis 未设置超时的情况', '', '2021-01-26 00:53:17', '', '2021-01-26 00:53:17', b'0'); @@ -380,7 +380,7 @@ INSERT INTO `sys_dict_type` VALUES (8, '通知状态', 'sys_notice_status', 0, N INSERT INTO `sys_dict_type` VALUES (9, '操作类型', 'sys_oper_type', 0, NULL, 'admin', '2021-01-05 17:03:48', '', '2021-01-05 17:03:48', b'0'); INSERT INTO `sys_dict_type` VALUES (10, '系统状态', 'sys_common_status', 0, NULL, 'admin', '2021-01-05 17:03:48', '', '2021-01-05 17:03:48', b'0'); INSERT INTO `sys_dict_type` VALUES (11, 'Boolean 是否类型', 'sys_boolean_string', 0, 'boolean 转是否', '', '2021-01-19 03:20:08', '', '2021-01-19 03:20:08', b'0'); -INSERT INTO `sys_dict_type` VALUES (104, '登陆结果', 'sys_login_result', 0, '登陆结果', '', '2021-01-18 06:17:11', '', '2021-01-18 06:17:11', b'0'); +INSERT INTO `sys_dict_type` VALUES (104, '登录结果', 'sys_login_result', 0, '登录结果', '', '2021-01-18 06:17:11', '', '2021-01-18 06:17:11', b'0'); INSERT INTO `sys_dict_type` VALUES (105, 'Redis 超时类型', 'inf_redis_timeout_type', 0, 'RedisKeyDefine.TimeoutTypeEnum', '', '2021-01-26 00:52:50', '', '2021-01-26 00:52:50', b'0'); INSERT INTO `sys_dict_type` VALUES (106, '代码生成模板类型', 'tool_codegen_template_type', 0, NULL, '', '2021-02-05 07:08:06', '', '2021-02-05 07:08:06', b'0'); INSERT INTO `sys_dict_type` VALUES (107, '定时任务状态', 'inf_job_status', 0, NULL, '', '2021-02-07 07:44:16', '', '2021-02-07 07:44:16', b'0'); @@ -392,7 +392,7 @@ INSERT INTO `sys_dict_type` VALUES (112, '短信模板的类型', 'sys_sms_templ INSERT INTO `sys_dict_type` VALUES (113, '短信发送状态', 'sys_sms_send_status', 0, NULL, '1', '2021-04-11 20:18:03', '1', '2021-04-11 09:30:02', b'0'); INSERT INTO `sys_dict_type` VALUES (114, '短信接收状态', 'sys_sms_receive_status', 0, NULL, '1', '2021-04-11 20:27:14', '1', '2021-04-11 20:27:14', b'0'); INSERT INTO `sys_dict_type` VALUES (115, '错误码的类型', 'sys_error_code_type', 0, NULL, '1', '2021-04-21 00:06:30', '1', '2021-04-13 22:07:12', b'0'); -INSERT INTO `sys_dict_type` VALUES (116, '登陆日志的类型', 'sys_login_type', 0, '登陆日志的类型', '1', '2021-10-06 00:50:46', '1', '2021-10-06 00:50:46', b'0'); +INSERT INTO `sys_dict_type` VALUES (116, '登录日志的类型', 'sys_login_type', 0, '登录日志的类型', '1', '2021-10-06 00:50:46', '1', '2021-10-06 00:50:46', b'0'); COMMIT; -- ---------------------------- @@ -511,7 +511,7 @@ CREATE TABLE `sys_login_log` ( `user_id` bigint NOT NULL DEFAULT '0' COMMENT '用户编号', `user_type` tinyint NOT NULL DEFAULT '0' COMMENT '用户类型', `username` varchar(50) NOT NULL DEFAULT '' COMMENT '用户账号', - `result` tinyint NOT NULL COMMENT '登陆结果', + `result` tinyint NOT NULL COMMENT '登录结果', `user_ip` varchar(50) NOT NULL COMMENT '用户 IP', `user_agent` varchar(512) NOT NULL COMMENT '浏览器 UA', `creator` varchar(64) DEFAULT '' COMMENT '创建者', diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/auth/SysAuthController.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/auth/SysAuthController.java index 4750d6264..c302bc312 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/auth/SysAuthController.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/auth/SysAuthController.java @@ -70,7 +70,7 @@ public class SysAuthController { } @GetMapping("/get-permission-info") - @ApiOperation("获取登陆用户的权限信息") + @ApiOperation("获取登录用户的权限信息") public CommonResult getPermissionInfo() { // 获得用户信息 SysUserDO user = userService.getUser(getLoginUserId()); @@ -81,7 +81,7 @@ public class SysAuthController { List roleList = roleService.getRolesFromCache(getLoginUserRoleIds()); // 获得菜单列表 List menuList = permissionService.getRoleMenusFromCache( - getLoginUserRoleIds(), // 注意,基于登陆的角色,因为后续的权限判断也是基于它 + getLoginUserRoleIds(), // 注意,基于登录的角色,因为后续的权限判断也是基于它 SetUtils.asSet(MenuTypeEnum.DIR.getType(), MenuTypeEnum.MENU.getType(), MenuTypeEnum.BUTTON.getType()), SetUtils.asSet(CommonStatusEnum.ENABLE.getStatus())); // 拼接结果返回 @@ -89,32 +89,32 @@ public class SysAuthController { } @GetMapping("list-menus") - @ApiOperation("获得登陆用户的菜单列表") + @ApiOperation("获得登录用户的菜单列表") public CommonResult> getMenus() { // 获得用户拥有的菜单列表 List menuList = permissionService.getRoleMenusFromCache( - getLoginUserRoleIds(), // 注意,基于登陆的角色,因为后续的权限判断也是基于它 + getLoginUserRoleIds(), // 注意,基于登录的角色,因为后续的权限判断也是基于它 SetUtils.asSet(MenuTypeEnum.DIR.getType(), MenuTypeEnum.MENU.getType()), // 只要目录和菜单类型 SetUtils.asSet(CommonStatusEnum.ENABLE.getStatus())); // 只要开启的 // 转换成 Tree 结构返回 return success(SysAuthConvert.INSTANCE.buildMenuTree(menuList)); } - // ========== 社交登陆相关 ========== + // ========== 社交登录相关 ========== - @GetMapping("/social-login-redirect") - @ApiOperation("社交登陆的跳转") + @GetMapping("/social-auth-redirect") + @ApiOperation("社交授权的跳转") @ApiImplicitParams({ @ApiImplicitParam(name = "type", value = "社交类型", required = true, dataTypeClass = Integer.class), @ApiImplicitParam(name = "redirectUri", value = "回调路径", dataTypeClass = String.class) }) - public CommonResult socialLoginRedirect(@RequestParam("type") Integer type, + public CommonResult socialAuthRedirect(@RequestParam("type") Integer type, @RequestParam("redirectUri") String redirectUri) { return CommonResult.success(socialService.getAuthorizeUrl(type, redirectUri)); } @PostMapping("/social-login") - @ApiOperation("社交登陆,使用 code 授权码") + @ApiOperation("社交登录,使用 code 授权码") @OperateLog(enable = false) // 避免 Post 请求被记录操作日志 public CommonResult socialLogin(@RequestBody @Valid SysAuthSocialLoginReqVO reqVO) { String token = authService.socialLogin(reqVO, getClientIP(), getUserAgent()); @@ -123,7 +123,7 @@ public class SysAuthController { } @PostMapping("/social-login2") - @ApiOperation("社交登陆,使用 code 授权码 + 账号密码") + @ApiOperation("社交登录,使用 code 授权码 + 账号密码") @OperateLog(enable = false) // 避免 Post 请求被记录操作日志 public CommonResult socialLogin2(@RequestBody @Valid SysAuthSocialLogin2ReqVO reqVO) { String token = authService.socialLogin2(reqVO, getClientIP(), getUserAgent()); @@ -131,4 +131,18 @@ public class SysAuthController { return success(SysAuthLoginRespVO.builder().token(token).build()); } + @PostMapping("/social-bind") + @ApiOperation("社交绑定,使用 code 授权码") + public CommonResult socialBind(@RequestBody @Valid SysAuthSocialBindReqVO reqVO) { + authService.socialBind(getLoginUserId(), reqVO); + return CommonResult.success(true); + } + + @DeleteMapping("/social-unbind") + @ApiOperation("取消社交绑定") + public CommonResult socialUnbind(@RequestBody SysAuthSocialUnbindReqVO reqVO) { + socialService.unbindSocialUser(getLoginUserId(), reqVO.getType(), reqVO.getUnionId()); + return CommonResult.success(true); + } + } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/auth/vo/auth/SysAuthLoginReqVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/auth/vo/auth/SysAuthLoginReqVO.java index 43df52c7f..366144ea2 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/auth/vo/auth/SysAuthLoginReqVO.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/auth/vo/auth/SysAuthLoginReqVO.java @@ -11,7 +11,7 @@ import org.hibernate.validator.constraints.Length; import javax.validation.constraints.NotEmpty; import javax.validation.constraints.Pattern; -@ApiModel("账号密码登陆 Request VO") +@ApiModel("账号密码登录 Request VO") @Data @NoArgsConstructor @AllArgsConstructor @@ -19,7 +19,7 @@ import javax.validation.constraints.Pattern; public class SysAuthLoginReqVO { @ApiModelProperty(value = "账号", required = true, example = "yudaoyuanma") - @NotEmpty(message = "登陆账号不能为空") + @NotEmpty(message = "登录账号不能为空") @Length(min = 4, max = 16, message = "账号长度为 4-16 位") @Pattern(regexp = "^[A-Za-z0-9]+$", message = "账号格式为数字以及字母") private String username; diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/auth/vo/auth/SysAuthLoginRespVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/auth/vo/auth/SysAuthLoginRespVO.java index c09bd03c3..381c3223e 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/auth/vo/auth/SysAuthLoginRespVO.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/auth/vo/auth/SysAuthLoginRespVO.java @@ -7,7 +7,7 @@ import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; -@ApiModel("账号密码登陆 Response VO") +@ApiModel("账号密码登录 Response VO") @Data @NoArgsConstructor @AllArgsConstructor diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/auth/vo/auth/SysAuthMenuRespVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/auth/vo/auth/SysAuthMenuRespVO.java index 3329c80d2..c39354b10 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/auth/vo/auth/SysAuthMenuRespVO.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/auth/vo/auth/SysAuthMenuRespVO.java @@ -9,7 +9,7 @@ import lombok.NoArgsConstructor; import java.util.List; -@ApiModel("登陆用户的菜单信息 Response VO") +@ApiModel("登录用户的菜单信息 Response VO") @Data @NoArgsConstructor @AllArgsConstructor diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/auth/vo/auth/SysAuthPermissionInfoRespVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/auth/vo/auth/SysAuthPermissionInfoRespVO.java index 102c3c939..39cc9679c 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/auth/vo/auth/SysAuthPermissionInfoRespVO.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/auth/vo/auth/SysAuthPermissionInfoRespVO.java @@ -9,7 +9,7 @@ import lombok.NoArgsConstructor; import java.util.Set; -@ApiModel(value = "登陆用户的权限信息 Response VO", description = "额外包括用户信息和角色列表") +@ApiModel(value = "登录用户的权限信息 Response VO", description = "额外包括用户信息和角色列表") @Data @NoArgsConstructor @AllArgsConstructor diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/auth/vo/auth/SysAuthSocialBindReqVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/auth/vo/auth/SysAuthSocialBindReqVO.java new file mode 100644 index 000000000..5b9bec053 --- /dev/null +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/auth/vo/auth/SysAuthSocialBindReqVO.java @@ -0,0 +1,35 @@ +package cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.auth; + +import cn.iocoder.yudao.adminserver.modules.system.enums.user.SysSocialTypeEnum; +import cn.iocoder.yudao.framework.common.validation.InEnum; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; + +@ApiModel("社交绑定 Request VO,使用 code 授权码") +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class SysAuthSocialBindReqVO { + + @ApiModelProperty(value = "社交平台的类型", required = true, example = "10", notes = "参见 SysUserSocialTypeEnum 枚举值") + @InEnum(SysSocialTypeEnum.class) + @NotNull(message = "社交平台的类型不能为空") + private Integer type; + + @ApiModelProperty(value = "授权码", required = true, example = "1024") + @NotEmpty(message = "授权码不能为空") + private String code; + + @ApiModelProperty(value = "state", required = true, example = "9b2ffbc1-7425-4155-9894-9d5c08541d62") + @NotEmpty(message = "state 不能为空") + private String state; + +} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/auth/vo/auth/SysAuthSocialLogin2ReqVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/auth/vo/auth/SysAuthSocialLogin2ReqVO.java index bca66ecd8..100656c27 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/auth/vo/auth/SysAuthSocialLogin2ReqVO.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/auth/vo/auth/SysAuthSocialLogin2ReqVO.java @@ -14,7 +14,7 @@ import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; import javax.validation.constraints.Pattern; -@ApiModel("社交登陆 Request VO,使用 code 授权码 + 账号密码") +@ApiModel("社交登录 Request VO,使用 code 授权码 + 账号密码") @Data @NoArgsConstructor @AllArgsConstructor @@ -35,7 +35,7 @@ public class SysAuthSocialLogin2ReqVO { private String state; @ApiModelProperty(value = "账号", required = true, example = "yudaoyuanma") - @NotEmpty(message = "登陆账号不能为空") + @NotEmpty(message = "登录账号不能为空") @Length(min = 4, max = 16, message = "账号长度为 4-16 位") @Pattern(regexp = "^[A-Za-z0-9]+$", message = "账号格式为数字以及字母") private String username; diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/auth/vo/auth/SysAuthSocialLoginReqVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/auth/vo/auth/SysAuthSocialLoginReqVO.java index 98f733c69..c6de997e6 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/auth/vo/auth/SysAuthSocialLoginReqVO.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/auth/vo/auth/SysAuthSocialLoginReqVO.java @@ -12,7 +12,7 @@ import lombok.NoArgsConstructor; import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; -@ApiModel("社交登陆 Request VO,使用 code 授权码") +@ApiModel("社交登录 Request VO,使用 code 授权码") @Data @NoArgsConstructor @AllArgsConstructor diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/auth/vo/auth/SysAuthSocialUnbindReqVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/auth/vo/auth/SysAuthSocialUnbindReqVO.java new file mode 100644 index 000000000..b851e94f6 --- /dev/null +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/auth/vo/auth/SysAuthSocialUnbindReqVO.java @@ -0,0 +1,31 @@ +package cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.auth; + +import cn.iocoder.yudao.adminserver.modules.system.enums.user.SysSocialTypeEnum; +import cn.iocoder.yudao.framework.common.validation.InEnum; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; + +@ApiModel("取消社交绑定 Request VO,使用 code 授权码") +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class SysAuthSocialUnbindReqVO { + + @ApiModelProperty(value = "社交平台的类型", required = true, example = "10", notes = "参见 SysUserSocialTypeEnum 枚举值") + @InEnum(SysSocialTypeEnum.class) + @NotNull(message = "社交平台的类型不能为空") + private Integer type; + + @ApiModelProperty(value = "社交的全局编号", required = true, example = "IPRmJ0wvBptiPIlGEZiPewGwiEiE") + @NotEmpty(message = "社交的全局编号不能为空") + private String unionId; + +} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/auth/vo/session/SysUserSessionPageItemRespVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/auth/vo/session/SysUserSessionPageItemRespVO.java index 1cb9a5af0..c67fa99ae 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/auth/vo/session/SysUserSessionPageItemRespVO.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/auth/vo/session/SysUserSessionPageItemRespVO.java @@ -26,7 +26,7 @@ public class SysUserSessionPageItemRespVO extends PageParam { @ApiModelProperty(value = "浏览器 UserAgent", required = true, example = "Mozilla/5.0") private String userAgent; - @ApiModelProperty(value = "登陆时间", required = true) + @ApiModelProperty(value = "登录时间", required = true) private Date createTime; @ApiModelProperty(value = "用户账号", required = true, example = "yudao") diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/logger/SysLoginLogController.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/logger/SysLoginLogController.java index 7af2cafeb..6f9a0d208 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/logger/SysLoginLogController.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/logger/SysLoginLogController.java @@ -27,7 +27,7 @@ import java.util.List; import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; -@Api(tags = "登陆日志") +@Api(tags = "登录日志") @RestController @RequestMapping("/system/login-log") @Validated @@ -37,7 +37,7 @@ public class SysLoginLogController { private SysLoginLogService loginLogService; @GetMapping("/page") - @ApiOperation("获得登陆日志分页列表") + @ApiOperation("获得登录日志分页列表") @PreAuthorize("@ss.hasPermission('system:login-log:query')") public CommonResult> getLoginLogPage(@Valid SysLoginLogPageReqVO reqVO) { PageResult page = loginLogService.getLoginLogPage(reqVO); @@ -45,7 +45,7 @@ public class SysLoginLogController { } @GetMapping("/export") - @ApiOperation("导出登陆日志 Excel") + @ApiOperation("导出登录日志 Excel") @PreAuthorize("@ss.hasPermission('system:login-log:export')") @OperateLog(type = EXPORT) public void exportLoginLog(HttpServletResponse response, @Valid SysLoginLogExportReqVO reqVO) throws IOException { @@ -53,7 +53,7 @@ public class SysLoginLogController { // 拼接数据 List data = SysLoginLogConvert.INSTANCE.convertList(list); // 输出 - ExcelUtils.write(response, "登陆日志.xls", "数据列表", SysLoginLogExcelVO.class, data); + ExcelUtils.write(response, "登录日志.xls", "数据列表", SysLoginLogExcelVO.class, data); } } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/logger/vo/loginlog/SysLoginLogBaseVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/logger/vo/loginlog/SysLoginLogBaseVO.java index 080f8f9bd..a346d946f 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/logger/vo/loginlog/SysLoginLogBaseVO.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/logger/vo/loginlog/SysLoginLogBaseVO.java @@ -9,7 +9,7 @@ import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; /** - * 登陆日志 Base VO,提供给添加、修改、详细的子 VO 使用 + * 登录日志 Base VO,提供给添加、修改、详细的子 VO 使用 * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 */ @Data @@ -28,8 +28,8 @@ public class SysLoginLogBaseVO { @Size(max = 30, message = "用户账号长度不能超过30个字符") private String username; - @ApiModelProperty(value = "登陆结果", required = true, example = "1", notes = "参见 SysLoginResultEnum 枚举类") - @NotNull(message = "登陆结果不能为空") + @ApiModelProperty(value = "登录结果", required = true, example = "1", notes = "参见 SysLoginResultEnum 枚举类") + @NotNull(message = "登录结果不能为空") private Integer result; @ApiModelProperty(value = "用户 IP", required = true, example = "127.0.0.1") diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/logger/vo/loginlog/SysLoginLogCreateReqVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/logger/vo/loginlog/SysLoginLogCreateReqVO.java index 6f915540c..738937806 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/logger/vo/loginlog/SysLoginLogCreateReqVO.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/logger/vo/loginlog/SysLoginLogCreateReqVO.java @@ -5,8 +5,8 @@ import lombok.Data; import lombok.EqualsAndHashCode; import lombok.ToString; -@ApiModel(value = "登陆日志创建 Request VO", - description = "暂时提供给前端,仅仅后端记录登陆日志时,进行使用") +@ApiModel(value = "登录日志创建 Request VO", + description = "暂时提供给前端,仅仅后端记录登录日志时,进行使用") @Data @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/logger/vo/loginlog/SysLoginLogExcelVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/logger/vo/loginlog/SysLoginLogExcelVO.java index b7e4631e3..852e9146a 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/logger/vo/loginlog/SysLoginLogExcelVO.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/logger/vo/loginlog/SysLoginLogExcelVO.java @@ -9,7 +9,7 @@ import lombok.Data; import java.util.Date; /** - * 登陆日志 Excel 导出响应 VO + * 登录日志 Excel 导出响应 VO */ @Data public class SysLoginLogExcelVO { @@ -24,17 +24,17 @@ public class SysLoginLogExcelVO { @DictFormat(SysDictTypeConstants.LOGIN_TYPE) private Integer logType; - @ExcelProperty(value = "登陆结果", converter = DictConvert.class) + @ExcelProperty(value = "登录结果", converter = DictConvert.class) @DictFormat(SysDictTypeConstants.LOGIN_RESULT) private Integer result; - @ExcelProperty("登陆 IP") + @ExcelProperty("登录 IP") private String userIp; @ExcelProperty("浏览器 UA") private String userAgent; - @ExcelProperty("登陆时间") + @ExcelProperty("登录时间") private Date createTime; } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/logger/vo/loginlog/SysLoginLogExportReqVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/logger/vo/loginlog/SysLoginLogExportReqVO.java index 1e706ddae..a85f92685 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/logger/vo/loginlog/SysLoginLogExportReqVO.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/logger/vo/loginlog/SysLoginLogExportReqVO.java @@ -9,7 +9,7 @@ import java.util.Date; import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; -@ApiModel("登陆日志分页列表 Request VO") +@ApiModel("登录日志分页列表 Request VO") @Data public class SysLoginLogExportReqVO { diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/logger/vo/loginlog/SysLoginLogPageReqVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/logger/vo/loginlog/SysLoginLogPageReqVO.java index 5b9389b58..52079094c 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/logger/vo/loginlog/SysLoginLogPageReqVO.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/logger/vo/loginlog/SysLoginLogPageReqVO.java @@ -11,7 +11,7 @@ import java.util.Date; import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; -@ApiModel("登陆日志分页列表 Request VO") +@ApiModel("登录日志分页列表 Request VO") @Data @EqualsAndHashCode(callSuper = true) public class SysLoginLogPageReqVO extends PageParam { diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/logger/vo/loginlog/SysLoginLogRespVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/logger/vo/loginlog/SysLoginLogRespVO.java index 8aaad9c03..65aa6494d 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/logger/vo/loginlog/SysLoginLogRespVO.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/logger/vo/loginlog/SysLoginLogRespVO.java @@ -9,7 +9,7 @@ import lombok.ToString; import javax.validation.constraints.NotNull; import java.util.Date; -@ApiModel("登陆日志 Response VO") +@ApiModel("登录日志 Response VO") @Data @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) @@ -26,7 +26,7 @@ public class SysLoginLogRespVO extends SysLoginLogBaseVO { @NotNull(message = "用户类型不能为空") private Integer userType; - @ApiModelProperty(value = "登陆时间", required = true) + @ApiModelProperty(value = "登录时间", required = true) private Date createTime; } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/user/SysUserProfileController.http b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/user/SysUserProfileController.http new file mode 100644 index 000000000..c0a817727 --- /dev/null +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/user/SysUserProfileController.http @@ -0,0 +1,3 @@ +### 请求 /system/user/profile/get 接口 => 没有权限 +GET {{baseUrl}}/system/user/profile/get +Authorization: Bearer test1 diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/user/SysUserProfileController.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/user/SysUserProfileController.java index 10640ace7..b00720ce2 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/user/SysUserProfileController.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/user/SysUserProfileController.java @@ -1,6 +1,8 @@ package cn.iocoder.yudao.adminserver.modules.system.controller.user; import cn.hutool.core.collection.CollUtil; +import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.social.SysSocialUserDO; +import cn.iocoder.yudao.adminserver.modules.system.service.social.SysSocialService; import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.profile.SysUserProfileRespVO; @@ -52,6 +54,8 @@ public class SysUserProfileController { private SysPermissionService permissionService; @Resource private SysRoleService roleService; + @Resource + private SysSocialService socialService; @GetMapping("/get") @ApiOperation("获得登录用户信息") @@ -72,6 +76,9 @@ public class SysUserProfileController { List posts = postService.getPosts(user.getPostIds()); resp.setPosts(SysUserConvert.INSTANCE.convertList02(posts)); } + // 获得社交用户信息 + List socialUsers = socialService.getSocialUserList(user.getId()); + resp.setSocialUsers(SysUserConvert.INSTANCE.convertList03(socialUsers)); return success(resp); } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/user/vo/profile/SysUserProfileRespVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/user/vo/profile/SysUserProfileRespVO.java index fddc09bdd..4269aaec0 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/user/vo/profile/SysUserProfileRespVO.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/user/vo/profile/SysUserProfileRespVO.java @@ -25,7 +25,7 @@ public class SysUserProfileRespVO extends SysUserBaseVO { @ApiModelProperty(value = "状态", required = true, example = "1", notes = "参见 SysCommonStatusEnum 枚举类") private Integer status; - @ApiModelProperty(value = "最后登陆 IP", required = true, example = "192.168.1.1") + @ApiModelProperty(value = "最后登录 IP", required = true, example = "192.168.1.1") private String loginIp; @ApiModelProperty(value = "最后登录时间", required = true, example = "时间戳格式") @@ -48,6 +48,10 @@ public class SysUserProfileRespVO extends SysUserBaseVO { * 所属岗位数组 */ private List posts; + /** + * 社交用户数组 + */ + private List socialUsers; @ApiModel("角色") @Data @@ -85,4 +89,16 @@ public class SysUserProfileRespVO extends SysUserBaseVO { } + @ApiModel("社交用户") + @Data + public static class SocialUser { + + @ApiModelProperty(value = "社交平台的类型", required = true, example = "10", notes = "参见 SysSocialTypeEnum 枚举类") + private Integer type; + + @ApiModelProperty(value = "社交的全局编号", required = true, example = "IPRmJ0wvBptiPIlGEZiPewGwiEiE") + private String unionId; + + } + } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/user/vo/user/SysUserRespVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/user/vo/user/SysUserRespVO.java index 8b68dbc8d..79abf64e5 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/user/vo/user/SysUserRespVO.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/user/vo/user/SysUserRespVO.java @@ -19,7 +19,7 @@ public class SysUserRespVO extends SysUserBaseVO { @ApiModelProperty(value = "状态", required = true, example = "1", notes = "参见 SysCommonStatusEnum 枚举类") private Integer status; - @ApiModelProperty(value = "最后登陆 IP", required = true, example = "192.168.1.1") + @ApiModelProperty(value = "最后登录 IP", required = true, example = "192.168.1.1") private String loginIp; @ApiModelProperty(value = "最后登录时间", required = true, example = "时间戳格式") diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/convert/user/SysUserConvert.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/convert/user/SysUserConvert.java index 7fddda876..7039cabe8 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/convert/user/SysUserConvert.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/convert/user/SysUserConvert.java @@ -7,6 +7,7 @@ import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.user.*; import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.dept.SysDeptDO; import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.dept.SysPostDO; import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.permission.SysRoleDO; +import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.social.SysSocialUserDO; import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.user.SysUserDO; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; @@ -42,4 +43,6 @@ public interface SysUserConvert { List convertList02(List list); + List convertList03(List list); + } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/dataobject/logger/SysLoginLogDO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/dataobject/logger/SysLoginLogDO.java index 3c05f3111..8bb80aa7a 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/dataobject/logger/SysLoginLogDO.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/dataobject/logger/SysLoginLogDO.java @@ -10,9 +10,9 @@ import lombok.EqualsAndHashCode; import lombok.ToString; /** - * 登陆日志表 + * 登录日志表 * - * 注意,包括登陆和登出两种行为 + * 注意,包括登录和登出两种行为 * * @author ruoyi */ @@ -53,7 +53,7 @@ public class SysLoginLogDO extends BaseDO { */ private String username; /** - * 登陆结果 + * 登录结果 * * 枚举 {@link SysLoginResultEnum} */ diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/mysql/social/SysSocialUserMapper.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/mysql/social/SysSocialUserMapper.java index 9c00b2136..b5762ec7f 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/mysql/social/SysSocialUserMapper.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/mysql/social/SysSocialUserMapper.java @@ -21,4 +21,8 @@ public interface SysSocialUserMapper extends BaseMapperX { .in("type", types).eq("user_id", userId)); } + default List selectListByUserId(Integer userType, Long userId) { + return selectList(new QueryWrapper().eq("user_type", userType).eq("user_id", userId)); + } + } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/redis/SysRedisKeyConstants.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/redis/SysRedisKeyConstants.java index f43e29b0d..78109c73c 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/redis/SysRedisKeyConstants.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/redis/SysRedisKeyConstants.java @@ -15,7 +15,7 @@ import static cn.iocoder.yudao.framework.redis.core.RedisKeyDefine.KeyTypeEnum.S */ public interface SysRedisKeyConstants { - RedisKeyDefine LOGIN_USER = new RedisKeyDefine("登陆用户的缓存", + RedisKeyDefine LOGIN_USER = new RedisKeyDefine("登录用户的缓存", "login_user:%s", // 参数为 sessionId STRING, LoginUser.class, RedisKeyDefine.TimeoutTypeEnum.DYNAMIC); diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/enums/SysDictTypeConstants.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/enums/SysDictTypeConstants.java index 974427097..64c1b5e81 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/enums/SysDictTypeConstants.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/enums/SysDictTypeConstants.java @@ -12,8 +12,8 @@ public interface SysDictTypeConstants { String USER_SEX = "sys_user_sex"; // 用户性别 String OPERATE_TYPE = "sys_operate_type"; // 操作类型 - String LOGIN_TYPE = "sys_login_type"; // 登陆日志的类型 - String LOGIN_RESULT = "sys_login_result"; // 登陆结果 + String LOGIN_TYPE = "sys_login_type"; // 登录日志的类型 + String LOGIN_RESULT = "sys_login_result"; // 登录结果 String CONFIG_TYPE = "sys_config_type"; // 参数配置类型 String BOOLEAN_STRING = "sys_boolean_string"; // Boolean 是否类型 diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/enums/SysErrorCodeConstants.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/enums/SysErrorCodeConstants.java index ad4598615..e7388cca8 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/enums/SysErrorCodeConstants.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/enums/SysErrorCodeConstants.java @@ -2,6 +2,7 @@ package cn.iocoder.yudao.adminserver.modules.system.enums; import cn.iocoder.yudao.adminserver.modules.tool.framework.errorcode.config.ErrorCodeConfiguration; import cn.iocoder.yudao.framework.common.exception.ErrorCode; +import org.springframework.validation.Errors; /** * System 错误码枚举类 @@ -13,7 +14,7 @@ public interface SysErrorCodeConstants { // ========== AUTH 模块 1002000000 ========== ErrorCode AUTH_LOGIN_BAD_CREDENTIALS = new ErrorCode(1002000000, "登录失败,账号密码不正确"); ErrorCode AUTH_LOGIN_USER_DISABLED = new ErrorCode(1002000001, "登录失败,账号被禁用"); - ErrorCode AUTH_LOGIN_FAIL_UNKNOWN = new ErrorCode(1002000002, "登录失败"); // 登陆失败的兜底,位置原因 + ErrorCode AUTH_LOGIN_FAIL_UNKNOWN = new ErrorCode(1002000002, "登录失败"); // 登录失败的兜底,位置原因 ErrorCode AUTH_LOGIN_CAPTCHA_NOT_FOUND = new ErrorCode(1002000003, "验证码不存在"); ErrorCode AUTH_LOGIN_CAPTCHA_CODE_ERROR = new ErrorCode(1002000004, "验证码不正确"); ErrorCode AUTH_THIRD_LOGIN_NOT_BIND = new ErrorCode(1002000005, "未绑定账号,需要进行绑定"); @@ -99,5 +100,6 @@ public interface SysErrorCodeConstants { // ========== 社交模块 1002014000 ========== ErrorCode SOCIAL_AUTH_FAILURE = new ErrorCode(1002014000, "社交授权失败,原因是:{}"); + ErrorCode SOCIAL_UNBIND_NOT_SELF = new ErrorCode(1002014001, "社交解绑失败,非当前用户绑定"); } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/enums/logger/SysLoginLogTypeEnum.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/enums/logger/SysLoginLogTypeEnum.java index 5e4c14984..3b56f2f08 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/enums/logger/SysLoginLogTypeEnum.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/enums/logger/SysLoginLogTypeEnum.java @@ -4,15 +4,15 @@ import lombok.AllArgsConstructor; import lombok.Getter; /** - * 登陆日志的类型枚举 + * 登录日志的类型枚举 */ @Getter @AllArgsConstructor public enum SysLoginLogTypeEnum { LOGIN_USERNAME(100), // 使用账号登录 - LOGIN_SOCIAL(101), // 使用社交登陆 - LOGIN_MOCK(102), // 使用 Mock 登陆 + LOGIN_SOCIAL(101), // 使用社交登录 + LOGIN_MOCK(102), // 使用 Mock 登录 LOGOUT_SELF(200), // 自己主动登出 LOGOUT_TIMEOUT(201), // 超时登出 diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/enums/logger/SysLoginResultEnum.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/enums/logger/SysLoginResultEnum.java index b34a9fecc..e1bdeb955 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/enums/logger/SysLoginResultEnum.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/enums/logger/SysLoginResultEnum.java @@ -4,7 +4,7 @@ import lombok.AllArgsConstructor; import lombok.Getter; /** - * 登陆结果的枚举类 + * 登录结果的枚举类 */ @Getter @AllArgsConstructor diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/auth/SysAuthService.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/auth/SysAuthService.java index 406179aa1..369f7c0b9 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/auth/SysAuthService.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/auth/SysAuthService.java @@ -1,47 +1,55 @@ package cn.iocoder.yudao.adminserver.modules.system.service.auth; -import cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.auth.SysAuthSocialLogin2ReqVO; -import cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.auth.SysAuthSocialLoginReqVO; +import cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.auth.*; import cn.iocoder.yudao.framework.security.core.service.SecurityAuthFrameworkService; -import cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.auth.SysAuthLoginReqVO; + +import javax.validation.Valid; /** * 认证 Service 接口 * - * 提供用户的账号密码登陆、token 的校验等认证相关的功能 + * 提供用户的账号密码登录、token 的校验等认证相关的功能 * * @author 芋道源码 */ public interface SysAuthService extends SecurityAuthFrameworkService { /** - * 登陆用户 + * 账号登录 * - * @param reqVO 登陆信息 + * @param reqVO 登录信息 * @param userIp 用户 IP * @param userAgent 用户 UA * @return 身份令牌,使用 JWT 方式 */ - String login(SysAuthLoginReqVO reqVO, String userIp, String userAgent); + String login(@Valid SysAuthLoginReqVO reqVO, String userIp, String userAgent); /** - * 社交登陆用户,使用 code 授权码 + * 社交登录,使用 code 授权码 * - * @param reqVO 登陆信息 + * @param reqVO 登录信息 * @param userIp 用户 IP * @param userAgent 用户 UA * @return 身份令牌,使用 JWT 方式 */ - String socialLogin(SysAuthSocialLoginReqVO reqVO, String userIp, String userAgent); + String socialLogin(@Valid SysAuthSocialLoginReqVO reqVO, String userIp, String userAgent); /** - * 社交登陆用户,使用 code 授权码 + 账号密码 + * 社交登录,使用 code 授权码 + 账号密码 * - * @param reqVO 登陆信息 + * @param reqVO 登录信息 * @param userIp 用户 IP * @param userAgent 用户 UA * @return 身份令牌,使用 JWT 方式 */ - String socialLogin2(SysAuthSocialLogin2ReqVO reqVO, String userIp, String userAgent); + String socialLogin2(@Valid SysAuthSocialLogin2ReqVO reqVO, String userIp, String userAgent); + + /** + * 社交绑定,使用 code 授权码 + * + * @param userId 用户编号 + * @param reqVO 绑定信息 + */ + void socialBind(Long userId, @Valid SysAuthSocialBindReqVO reqVO); } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/auth/SysUserSessionService.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/auth/SysUserSessionService.java index 4be724fde..900ed1c0a 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/auth/SysUserSessionService.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/auth/SysUserSessionService.java @@ -15,7 +15,7 @@ public interface SysUserSessionService { /** * 创建在线用户 Session * - * @param loginUser 登陆用户 + * @param loginUser 登录用户 * @param userIp 用户 IP * @param userAgent 用户 UA * @return Session 编号 @@ -26,7 +26,7 @@ public interface SysUserSessionService { * 刷新在线用户 Session 的更新时间 * * @param sessionId Session 编号 - * @param loginUser 登陆用户 + * @param loginUser 登录用户 */ void refreshUserSession(String sessionId, LoginUser loginUser); diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/auth/impl/SysAuthServiceImpl.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/auth/impl/SysAuthServiceImpl.java index 0368afb52..a17042822 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/auth/impl/SysAuthServiceImpl.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/auth/impl/SysAuthServiceImpl.java @@ -2,6 +2,7 @@ package cn.iocoder.yudao.adminserver.modules.system.service.auth.impl; import cn.hutool.core.collection.CollUtil; import cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.auth.SysAuthLoginReqVO; +import cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.auth.SysAuthSocialBindReqVO; import cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.auth.SysAuthSocialLogin2ReqVO; import cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.auth.SysAuthSocialLoginReqVO; import cn.iocoder.yudao.adminserver.modules.system.controller.logger.vo.loginlog.SysLoginLogCreateReqVO; @@ -18,7 +19,6 @@ import cn.iocoder.yudao.adminserver.modules.system.service.permission.SysPermiss import cn.iocoder.yudao.adminserver.modules.system.service.social.SysSocialService; import cn.iocoder.yudao.adminserver.modules.system.service.user.SysUserService; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; -import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil; import cn.iocoder.yudao.framework.common.util.monitor.TracerUtils; import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils; import cn.iocoder.yudao.framework.security.core.LoginUser; @@ -101,11 +101,11 @@ public class SysAuthServiceImpl implements SysAuthService { // 判断验证码是否正确 this.verifyCaptcha(reqVO.getUsername(), reqVO.getUuid(), reqVO.getCode()); - // 使用账号密码,进行登陆。 + // 使用账号密码,进行登录。 LoginUser loginUser = this.login0(reqVO.getUsername(), reqVO.getPassword()); loginUser.setRoleIds(this.getUserRoleIds(loginUser.getId())); // 获取用户角色列表 - // 缓存登陆用户到 Redis 中,返回 sessionId 编号 + // 缓存登录用户到 Redis 中,返回 sessionId 编号 return userSessionService.createUserSession(loginUser, userIp, userAgent); } @@ -114,13 +114,13 @@ public class SysAuthServiceImpl implements SysAuthService { String code = captchaService.getCaptchaCode(captchaUUID); // 验证码不存在 if (code == null) { - // 创建登陆失败日志(验证码不存在) + // 创建登录失败日志(验证码不存在) this.createLoginLog(username, logTypeEnum, SysLoginResultEnum.CAPTCHA_NOT_FOUND); throw exception(AUTH_LOGIN_CAPTCHA_NOT_FOUND); } // 验证码不正确 if (!code.equals(captchaCode)) { - // 创建登陆失败日志(验证码不正确) + // 创建登录失败日志(验证码不正确) this.createLoginLog(username, logTypeEnum, SysLoginResultEnum.CAPTCHA_CODE_ERROR); throw exception(AUTH_LOGIN_CAPTCHA_CODE_ERROR); } @@ -147,7 +147,7 @@ public class SysAuthServiceImpl implements SysAuthService { this.createLoginLog(username, logTypeEnum, SysLoginResultEnum.UNKNOWN_ERROR); throw exception(AUTH_LOGIN_FAIL_UNKNOWN); } - // 登陆成功的日志 + // 登录成功的日志 Assert.notNull(authentication.getPrincipal(), "Principal 不会为空"); this.createLoginLog(username, logTypeEnum, SysLoginResultEnum.SUCCESS); return (LoginUser) authentication.getPrincipal(); @@ -176,18 +176,18 @@ public class SysAuthServiceImpl implements SysAuthService { @Override public String socialLogin(SysAuthSocialLoginReqVO reqVO, String userIp, String userAgent) { - // 使用 code 授权码,进行登陆 + // 使用 code 授权码,进行登录 AuthUser authUser = socialService.getAuthUser(reqVO.getType(), reqVO.getCode(), reqVO.getState()); Assert.notNull(authUser, "授权用户不为空"); - // 如果未绑定 SysSocialUserDO 用户,则无法自动登陆,进行报错 + // 如果未绑定 SysSocialUserDO 用户,则无法自动登录,进行报错 String unionId = socialService.getAuthUserUnionId(authUser); List socialUsers = socialService.getAllSocialUserList(reqVO.getType(), unionId); if (CollUtil.isEmpty(socialUsers)) { throw exception(AUTH_THIRD_LOGIN_NOT_BIND); } - // 自动登陆 + // 自动登录 SysUserDO user = userService.getUser(socialUsers.get(0).getUserId()); if (user == null) { throw exception(USER_NOT_EXISTS); @@ -196,33 +196,43 @@ public class SysAuthServiceImpl implements SysAuthService { // 创建 LoginUser 对象 LoginUser loginUser = SysAuthConvert.INSTANCE.convert(user); - // TODO 芋艿:需要改造下,增加各种登陆方式 + // TODO 芋艿:需要改造下,增加各种登录方式 loginUser.setRoleIds(this.getUserRoleIds(loginUser.getId())); // 获取用户角色列表 // 绑定社交用户(更新) socialService.bindSocialUser(loginUser.getId(), reqVO.getType(), authUser); - // 缓存登陆用户到 Redis 中,返回 sessionId 编号 + // 缓存登录用户到 Redis 中,返回 sessionId 编号 return userSessionService.createUserSession(loginUser, userIp, userAgent); } @Override public String socialLogin2(SysAuthSocialLogin2ReqVO reqVO, String userIp, String userAgent) { - // 使用 code 授权码,进行登陆 + // 使用 code 授权码,进行登录 AuthUser authUser = socialService.getAuthUser(reqVO.getType(), reqVO.getCode(), reqVO.getState()); Assert.notNull(authUser, "授权用户不为空"); - // 使用账号密码,进行登陆。 + // 使用账号密码,进行登录。 LoginUser loginUser = this.login0(reqVO.getUsername(), reqVO.getPassword()); loginUser.setRoleIds(this.getUserRoleIds(loginUser.getId())); // 获取用户角色列表 // 绑定社交用户(新增) socialService.bindSocialUser(loginUser.getId(), reqVO.getType(), authUser); - // 缓存登陆用户到 Redis 中,返回 sessionId 编号 + // 缓存登录用户到 Redis 中,返回 sessionId 编号 return userSessionService.createUserSession(loginUser, userIp, userAgent); } + @Override + public void socialBind(Long userId, SysAuthSocialBindReqVO reqVO) { + // 使用 code 授权码,进行登录 + AuthUser authUser = socialService.getAuthUser(reqVO.getType(), reqVO.getCode(), reqVO.getState()); + Assert.notNull(authUser, "授权用户不为空"); + + // 绑定社交用户(新增) + socialService.bindSocialUser(userId, reqVO.getType(), authUser); + } + @Override public void logout(String token) { // 查询用户信息 @@ -269,7 +279,7 @@ public class SysAuthServiceImpl implements SysAuthService { // 重新加载 SysUserDO 信息 SysUserDO user = userService.getUser(loginUser.getId()); if (user == null || CommonStatusEnum.DISABLE.getStatus().equals(user.getStatus())) { - throw exception(TOKEN_EXPIRED); // 校验 token 时,用户被禁用的情况下,也认为 token 过期,方便前端跳转到登陆界面 + throw exception(TOKEN_EXPIRED); // 校验 token 时,用户被禁用的情况下,也认为 token 过期,方便前端跳转到登录界面 } // 刷新 LoginUser 缓存 diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/logger/SysLoginLogService.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/logger/SysLoginLogService.java index 9da2570fb..fd4ad6658 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/logger/SysLoginLogService.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/logger/SysLoginLogService.java @@ -9,30 +9,30 @@ import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.logger.SysLogi import java.util.List; /** - * 登陆日志 Service 接口 + * 登录日志 Service 接口 */ public interface SysLoginLogService { /** - * 创建登陆日志 + * 创建登录日志 * * @param reqVO 日志信息 */ void createLoginLog(SysLoginLogCreateReqVO reqVO); /** - * 获得登陆日志分页 + * 获得登录日志分页 * * @param reqVO 分页条件 - * @return 登陆日志分页 + * @return 登录日志分页 */ PageResult getLoginLogPage(SysLoginLogPageReqVO reqVO); /** - * 获得登陆日志列表 + * 获得登录日志列表 * * @param reqVO 列表条件 - * @return 登陆日志列表 + * @return 登录日志列表 */ List getLoginLogList(SysLoginLogExportReqVO reqVO); diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/logger/impl/SysLoginLogServiceImpl.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/logger/impl/SysLoginLogServiceImpl.java index 1b81a11ae..b5a7b3500 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/logger/impl/SysLoginLogServiceImpl.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/logger/impl/SysLoginLogServiceImpl.java @@ -17,7 +17,7 @@ import javax.annotation.Resource; import java.util.List; /** - * 登陆日志 Service 实现 + * 登录日志 Service 实现 */ @Service public class SysLoginLogServiceImpl implements SysLoginLogService { diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/permission/impl/SysPermissionServiceImpl.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/permission/impl/SysPermissionServiceImpl.java index 64bf04f26..b4eb2cb34 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/permission/impl/SysPermissionServiceImpl.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/permission/impl/SysPermissionServiceImpl.java @@ -280,7 +280,7 @@ public class SysPermissionServiceImpl implements SysPermissionService { return true; } - // 获得当前登陆的角色。如果为空,说明没有权限 + // 获得当前登录的角色。如果为空,说明没有权限 Set roleIds = SecurityFrameworkUtils.getLoginUserRoleIds(); if (CollUtil.isEmpty(roleIds)) { return false; @@ -315,7 +315,7 @@ public class SysPermissionServiceImpl implements SysPermissionService { return true; } - // 获得当前登陆的角色。如果为空,说明没有权限 + // 获得当前登录的角色。如果为空,说明没有权限 Set roleIds = SecurityFrameworkUtils.getLoginUserRoleIds(); if (CollUtil.isEmpty(roleIds)) { return false; diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/social/SysSocialService.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/social/SysSocialService.java index fdbc0dc28..a86cd21af 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/social/SysSocialService.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/social/SysSocialService.java @@ -4,6 +4,7 @@ import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.social.SysSocialUserDO; import cn.iocoder.yudao.adminserver.modules.system.enums.user.SysSocialTypeEnum; import cn.iocoder.yudao.framework.common.exception.ServiceException; +import io.swagger.models.auth.In; import me.zhyd.oauth.model.AuthUser; import javax.validation.constraints.NotNull; @@ -51,6 +52,14 @@ public interface SysSocialService { */ List getAllSocialUserList(Integer type, String unionId); + /** + * 获得指定用户的社交用户列表 + * + * @param userId 用户编号 + * @return 社交用户列表 + */ + List getSocialUserList(Long userId); + /** * 绑定社交用户 * @@ -60,4 +69,13 @@ public interface SysSocialService { */ void bindSocialUser(Long userId, Integer type, AuthUser authUser); + /** + * 取消绑定社交用户 + * + * @param userId 用户编号 + * @param type 社交平台的类型 {@link SysSocialTypeEnum} + * @param unionId 社交平台的 unionId + */ + void unbindSocialUser(Long userId, Integer type, String unionId); + } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/social/impl/SysSocialServiceImpl.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/social/impl/SysSocialServiceImpl.java index d250fdd8a..3bbbceb76 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/social/impl/SysSocialServiceImpl.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/social/impl/SysSocialServiceImpl.java @@ -9,7 +9,6 @@ import cn.iocoder.yudao.adminserver.modules.system.service.social.SysSocialServi import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.framework.common.util.http.HttpUtils; -import cn.iocoder.yudao.framework.common.util.json.JsonUtils; import com.xkcoding.justauth.AuthRequestFactory; import lombok.extern.slf4j.Slf4j; import me.zhyd.oauth.model.AuthCallback; @@ -18,15 +17,17 @@ import me.zhyd.oauth.model.AuthUser; import me.zhyd.oauth.request.AuthRequest; import me.zhyd.oauth.utils.AuthStateUtils; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import javax.validation.Valid; - import java.util.List; import java.util.Objects; import static cn.iocoder.yudao.adminserver.modules.system.enums.SysErrorCodeConstants.SOCIAL_AUTH_FAILURE; +import static cn.iocoder.yudao.adminserver.modules.system.enums.SysErrorCodeConstants.SOCIAL_UNBIND_NOT_SELF; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.framework.common.util.json.JsonUtils.toJsonString; /** * 社交 Service 实现类 @@ -67,7 +68,7 @@ public class SysSocialServiceImpl implements SysSocialService { // 请求获取 authUser = this.getAuthUser0(type, authCallback); - // 缓存。原因是 code 有且可以使用一次。在社交登录时,当未绑定 User 时,需要绑定登陆,此时需要 code 使用两次 + // 缓存。原因是 code 有且可以使用一次。在社交登录时,当未绑定 User 时,需要绑定登录,此时需要 code 使用两次 authSocialUserRedisDAO.set(type, authCallback, authUser); return authUser; } @@ -79,18 +80,19 @@ public class SysSocialServiceImpl implements SysSocialService { } @Override + public List getSocialUserList(Long userId) { + return socialUserMapper.selectListByUserId(UserTypeEnum.ADMIN.getValue(), userId); + } + + @Override + @Transactional public void bindSocialUser(Long userId, Integer type, AuthUser authUser) { // 获得 unionId 对应的 SysSocialUserDO 列表 String unionId = getAuthUserUnionId(authUser); List socialUsers = this.getAllSocialUserList(type, unionId); // 逻辑一:如果 userId 之前绑定过该 type 的其它账号,需要进行解绑 - List types = SysSocialTypeEnum.getRelationTypes(type); - List oldSocialUsers = socialUserMapper.selectListByTypeAndUserId(UserTypeEnum.ADMIN.getValue(), - types, userId); - if (CollUtil.isNotEmpty(oldSocialUsers) && !Objects.equals(unionId, oldSocialUsers.get(0).getUnionId())) { - socialUserMapper.deleteBatchIds(CollectionUtils.convertSet(oldSocialUsers, SysSocialUserDO::getId)); - } + this.unbindOldSocialUser(userId, type, unionId); // 逻辑二:如果 socialUsers 指定的 userId 改变,需要进行更新 // 例如说,一个微信 unionId 对应了多个社交账号,结果其中有个关联了新的 userId,则其它也要跟着修改 @@ -103,25 +105,52 @@ public class SysSocialServiceImpl implements SysSocialService { }); // 逻辑三:如果 authUser 不存在于 socialUsers 中,则进行新增;否则,进行更新 - SysSocialUserDO saveSocialUser = CollUtil.findOneByField(socialUsers, "openid", authUser.getUuid()); - if (saveSocialUser == null) { - saveSocialUser = new SysSocialUserDO(); - saveSocialUser.setUserId(userId).setUserType(UserTypeEnum.ADMIN.getValue()); - saveSocialUser.setType(type).setOpenid(authUser.getUuid()).setToken(authUser.getToken().getAccessToken()) - .setUnionId(unionId).setRawTokenInfo(JsonUtils.toJsonString(authUser.getToken())); - saveSocialUser.setNickname(authUser.getNickname()).setAvatar(authUser.getAvatar()) - .setRawUserInfo(JsonUtils.toJsonString(authUser.getRawUserInfo())); + SysSocialUserDO socialUser = CollUtil.findOneByField(socialUsers, "openid", authUser.getUuid()); + SysSocialUserDO saveSocialUser = SysSocialUserDO.builder() // 新增和更新的通用属性 + .token(authUser.getToken().getAccessToken()).rawUserInfo(toJsonString(authUser.getToken())) + .nickname(authUser.getNickname()).avatar(authUser.getAvatar()).rawUserInfo(toJsonString(authUser.getRawUserInfo())) + .build(); + if (socialUser == null) { + saveSocialUser.setUserId(userId).setUserType(UserTypeEnum.ADMIN.getValue()) + .setType(type).setOpenid(authUser.getUuid()).setUnionId(unionId); socialUserMapper.insert(saveSocialUser); } else { - saveSocialUser = new SysSocialUserDO().setId(saveSocialUser.getId()); - saveSocialUser.setToken(authUser.getToken().getAccessToken()) - .setRawTokenInfo(JsonUtils.toJsonString(authUser.getToken())); - saveSocialUser.setNickname(authUser.getNickname()).setAvatar(authUser.getAvatar()) - .setRawUserInfo(JsonUtils.toJsonString(authUser.getRawUserInfo())); + saveSocialUser.setId(socialUser.getId()); socialUserMapper.updateById(saveSocialUser); } } + @Override + public void unbindSocialUser(Long userId, Integer type, String unionId) { + // 获得 unionId 对应的所有 SysSocialUserDO 社交用户 + List socialUsers = this.getAllSocialUserList(type, unionId); + if (CollUtil.isEmpty(socialUsers)) { + return; + } + // 校验,是否解绑的是非自己的 + socialUsers.forEach(socialUser -> { + if (Objects.equals(socialUser.getUserId(), userId)) { + throw exception(SOCIAL_UNBIND_NOT_SELF); + } + }); + + // 解绑 + socialUserMapper.deleteBatchIds(CollectionUtils.convertSet(socialUsers, SysSocialUserDO::getId)); + } + + private void unbindOldSocialUser(Long userId, Integer type, String newUnionId) { + List types = SysSocialTypeEnum.getRelationTypes(type); + List oldSocialUsers = socialUserMapper.selectListByTypeAndUserId(UserTypeEnum.ADMIN.getValue(), + types, userId); + // 如果新老的 unionId 是一致的,说明无需解绑 + if (CollUtil.isEmpty(oldSocialUsers) || Objects.equals(newUnionId, oldSocialUsers.get(0).getUnionId())) { + return; + } + + // 解绑 + socialUserMapper.deleteBatchIds(CollectionUtils.convertSet(oldSocialUsers, SysSocialUserDO::getId)); + } + /** * 请求社交平台,获得授权的用户 * @@ -132,8 +161,8 @@ public class SysSocialServiceImpl implements SysSocialService { private AuthUser getAuthUser0(Integer type, AuthCallback authCallback) { AuthRequest authRequest = authRequestFactory.get(SysSocialTypeEnum.valueOfType(type).getSource()); AuthResponse authResponse = authRequest.login(authCallback); - log.info("[getAuthUser0][请求社交平台 type({}) request({}) response({})]", type, JsonUtils.toJsonString(authCallback), - JsonUtils.toJsonString(authResponse)); + log.info("[getAuthUser0][请求社交平台 type({}) request({}) response({})]", type, toJsonString(authCallback), + toJsonString(authResponse)); if (!authResponse.ok()) { throw exception(SOCIAL_AUTH_FAILURE, authResponse.getMsg()); } diff --git a/yudao-admin-server/src/test-integration/java/cn/iocoder/yudao/adminserver/modules/system/service/sms/SysSmsServiceIntegrationTest.java b/yudao-admin-server/src/test-integration/java/cn/iocoder/yudao/adminserver/modules/system/service/sms/SysSmsServiceIntegrationTest.java index bb43560d2..7bbaab67a 100644 --- a/yudao-admin-server/src/test-integration/java/cn/iocoder/yudao/adminserver/modules/system/service/sms/SysSmsServiceIntegrationTest.java +++ b/yudao-admin-server/src/test-integration/java/cn/iocoder/yudao/adminserver/modules/system/service/sms/SysSmsServiceIntegrationTest.java @@ -41,7 +41,7 @@ public class SysSmsServiceIntegrationTest extends BaseDbAndRedisIntegrationTest Integer userType = UserTypeEnum.ADMIN.getValue(); String templateCode = "test_01"; Map templateParams = MapUtil.builder() - .put("operation", "登陆").put("code", "1234").build(); + .put("operation", "登录").put("code", "1234").build(); // 调用 smsService.sendSingleSms(mobile, userId, userType, templateCode, templateParams); diff --git a/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/system/service/auth/SysAuthServiceImplTest.java b/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/system/service/auth/SysAuthServiceImplTest.java index 092d72fe7..ed00a6690 100644 --- a/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/system/service/auth/SysAuthServiceImplTest.java +++ b/yudao-admin-server/src/test/java/cn/iocoder/yudao/adminserver/modules/system/service/auth/SysAuthServiceImplTest.java @@ -236,7 +236,7 @@ public class SysAuthServiceImplTest extends BaseDbUnitTest { when(authentication.getPrincipal()).thenReturn(loginUser); // mock 获得 User 拥有的角色编号数组 when(permissionService.getUserRoleIds(userId, singleton(CommonStatusEnum.ENABLE.getStatus()))).thenReturn(userRoleIds); - // mock 缓存登陆用户到 Redis + // mock 缓存登录用户到 Redis when(userSessionService.createUserSession(loginUser, userIp, userAgent)).thenReturn(sessionId); // 调用, 并断言异常 String login = authService.login(reqVO, userIp, userAgent); diff --git a/yudao-admin-ui/src/api/login.js b/yudao-admin-ui/src/api/login.js index 4517ee42d..a02402d16 100644 --- a/yudao-admin-ui/src/api/login.js +++ b/yudao-admin-ui/src/api/login.js @@ -39,15 +39,15 @@ export function getCodeImg() { }) } -// 社交登陆的跳转 -export function socialLoginRedirect(type, redirectUri) { +// 社交授权的跳转 +export function socialAuthRedirect(type, redirectUri) { return request({ - url: '/social-login-redirect?type=' + type + '&redirectUri=' + redirectUri, + url: '/social-auth-redirect?type=' + type + '&redirectUri=' + redirectUri, method: 'get' }) } -// 社交登陆,使用 code 授权码 +// 社交登录,使用 code 授权码 export function socialLogin(type, code, state) { return request({ url: '/social-login', @@ -60,7 +60,7 @@ export function socialLogin(type, code, state) { }) } -// 社交登陆,使用 code 授权码 + + 账号密码 +// 社交登录,使用 code 授权码 + + 账号密码 export function socialLogin2(type, code, state, username, password) { return request({ url: '/social-login2', diff --git a/yudao-admin-ui/src/store/modules/user.js b/yudao-admin-ui/src/store/modules/user.js index 42560ae29..e9c4286af 100644 --- a/yudao-admin-ui/src/store/modules/user.js +++ b/yudao-admin-ui/src/store/modules/user.js @@ -47,7 +47,7 @@ const user = { }) }, - // 社交登陆 + // 社交登录 SocialLogin({ commit }, userInfo) { const code = userInfo.code const state = userInfo.state @@ -64,7 +64,7 @@ const user = { }) }, - // 社交登陆 + // 社交登录 SocialLogin2({ commit }, userInfo) { const code = userInfo.code const state = userInfo.state diff --git a/yudao-admin-ui/src/views/index_old.vue b/yudao-admin-ui/src/views/index_old.vue index 38c0a4e29..59c1bd187 100644 --- a/yudao-admin-ui/src/views/index_old.vue +++ b/yudao-admin-ui/src/views/index_old.vue @@ -419,7 +419,7 @@
  • 修复表格时间为空出现的异常
  • 添加Jackson日期反序列化时区配置
  • 调整根据用户权限加载菜单数据树形结构
  • -
  • 调整成功登陆不恢复按钮,防止多次点击
  • +
  • 调整成功登录不恢复按钮,防止多次点击
  • 修改用户个人资料同步缓存信息
  • 修复页面同时出现el-upload和Editor不显示处理
  • 修复在角色管理页修改菜单权限偶尔未选中问题
  • diff --git a/yudao-admin-ui/src/views/login.vue b/yudao-admin-ui/src/views/login.vue index 243da1768..d963e24c3 100644 --- a/yudao-admin-ui/src/views/login.vue +++ b/yudao-admin-ui/src/views/login.vue @@ -45,7 +45,7 @@