Commit 4a23a696f421331990974d30f69d95700aeb9fe4
1 parent
e8e6024a
1. 修复“登陆”=》“登录”
2. 增加社交平台的绑定与解绑
Showing
56 changed files
with
329 additions
and
149 deletions
README.md
| ... | ... | @@ -127,11 +127,11 @@ |
| 127 | 127 | |
| 128 | 128 | | 模块 | biu | biu | biu | |
| 129 | 129 | | --- | --- | --- | --- | |
| 130 | -| 登陆 & 首页 |  |  |  | | |
| 130 | +| 登录 & 首页 |  |  |  | | |
| 131 | 131 | | 用户 |  |  | - | |
| 132 | 132 | | 部门 & 岗位 |  |  | - | |
| 133 | 133 | | 菜单 & 角色 |  |  | - | |
| 134 | -| 审计日志 |  |  | - | | |
| 134 | +| 审计日志 |  |  | - | | |
| 135 | 135 | | 短信 |  |  |  | |
| 136 | 136 | | 字典 |  |  | - | |
| 137 | 137 | | 错误码 & 通知 |  |  | - | | ... | ... |
sql/ruoyi-vue-pro.sql
| ... | ... | @@ -299,12 +299,12 @@ INSERT INTO `sys_dict_data` VALUES (35, 2, '指定部门数据权限', '2', 'sys |
| 299 | 299 | 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'); |
| 300 | 300 | 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'); |
| 301 | 301 | 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'); |
| 302 | -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'); | |
| 303 | -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'); | |
| 304 | -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'); | |
| 305 | -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'); | |
| 306 | -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'); | |
| 307 | -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'); | |
| 302 | +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'); | |
| 303 | +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'); | |
| 304 | +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'); | |
| 305 | +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'); | |
| 306 | +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'); | |
| 307 | +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'); | |
| 308 | 308 | 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'); |
| 309 | 309 | 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'); |
| 310 | 310 | 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 |
| 380 | 380 | 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'); |
| 381 | 381 | 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'); |
| 382 | 382 | 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'); |
| 383 | -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'); | |
| 383 | +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'); | |
| 384 | 384 | 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'); |
| 385 | 385 | 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'); |
| 386 | 386 | 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 |
| 392 | 392 | 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'); |
| 393 | 393 | 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'); |
| 394 | 394 | 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'); |
| 395 | -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'); | |
| 395 | +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'); | |
| 396 | 396 | COMMIT; |
| 397 | 397 | |
| 398 | 398 | -- ---------------------------- |
| ... | ... | @@ -511,7 +511,7 @@ CREATE TABLE `sys_login_log` ( |
| 511 | 511 | `user_id` bigint NOT NULL DEFAULT '0' COMMENT '用户编号', |
| 512 | 512 | `user_type` tinyint NOT NULL DEFAULT '0' COMMENT '用户类型', |
| 513 | 513 | `username` varchar(50) NOT NULL DEFAULT '' COMMENT '用户账号', |
| 514 | - `result` tinyint NOT NULL COMMENT '登陆结果', | |
| 514 | + `result` tinyint NOT NULL COMMENT '登录结果', | |
| 515 | 515 | `user_ip` varchar(50) NOT NULL COMMENT '用户 IP', |
| 516 | 516 | `user_agent` varchar(512) NOT NULL COMMENT '浏览器 UA', |
| 517 | 517 | `creator` varchar(64) DEFAULT '' COMMENT '创建者', | ... | ... |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/auth/SysAuthController.java
| ... | ... | @@ -70,7 +70,7 @@ public class SysAuthController { |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | @GetMapping("/get-permission-info") |
| 73 | - @ApiOperation("获取登陆用户的权限信息") | |
| 73 | + @ApiOperation("获取登录用户的权限信息") | |
| 74 | 74 | public CommonResult<SysAuthPermissionInfoRespVO> getPermissionInfo() { |
| 75 | 75 | // 获得用户信息 |
| 76 | 76 | SysUserDO user = userService.getUser(getLoginUserId()); |
| ... | ... | @@ -81,7 +81,7 @@ public class SysAuthController { |
| 81 | 81 | List<SysRoleDO> roleList = roleService.getRolesFromCache(getLoginUserRoleIds()); |
| 82 | 82 | // 获得菜单列表 |
| 83 | 83 | List<SysMenuDO> menuList = permissionService.getRoleMenusFromCache( |
| 84 | - getLoginUserRoleIds(), // 注意,基于登陆的角色,因为后续的权限判断也是基于它 | |
| 84 | + getLoginUserRoleIds(), // 注意,基于登录的角色,因为后续的权限判断也是基于它 | |
| 85 | 85 | SetUtils.asSet(MenuTypeEnum.DIR.getType(), MenuTypeEnum.MENU.getType(), MenuTypeEnum.BUTTON.getType()), |
| 86 | 86 | SetUtils.asSet(CommonStatusEnum.ENABLE.getStatus())); |
| 87 | 87 | // 拼接结果返回 |
| ... | ... | @@ -89,32 +89,32 @@ public class SysAuthController { |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | @GetMapping("list-menus") |
| 92 | - @ApiOperation("获得登陆用户的菜单列表") | |
| 92 | + @ApiOperation("获得登录用户的菜单列表") | |
| 93 | 93 | public CommonResult<List<SysAuthMenuRespVO>> getMenus() { |
| 94 | 94 | // 获得用户拥有的菜单列表 |
| 95 | 95 | List<SysMenuDO> menuList = permissionService.getRoleMenusFromCache( |
| 96 | - getLoginUserRoleIds(), // 注意,基于登陆的角色,因为后续的权限判断也是基于它 | |
| 96 | + getLoginUserRoleIds(), // 注意,基于登录的角色,因为后续的权限判断也是基于它 | |
| 97 | 97 | SetUtils.asSet(MenuTypeEnum.DIR.getType(), MenuTypeEnum.MENU.getType()), // 只要目录和菜单类型 |
| 98 | 98 | SetUtils.asSet(CommonStatusEnum.ENABLE.getStatus())); // 只要开启的 |
| 99 | 99 | // 转换成 Tree 结构返回 |
| 100 | 100 | return success(SysAuthConvert.INSTANCE.buildMenuTree(menuList)); |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | - // ========== 社交登陆相关 ========== | |
| 103 | + // ========== 社交登录相关 ========== | |
| 104 | 104 | |
| 105 | - @GetMapping("/social-login-redirect") | |
| 106 | - @ApiOperation("社交登陆的跳转") | |
| 105 | + @GetMapping("/social-auth-redirect") | |
| 106 | + @ApiOperation("社交授权的跳转") | |
| 107 | 107 | @ApiImplicitParams({ |
| 108 | 108 | @ApiImplicitParam(name = "type", value = "社交类型", required = true, dataTypeClass = Integer.class), |
| 109 | 109 | @ApiImplicitParam(name = "redirectUri", value = "回调路径", dataTypeClass = String.class) |
| 110 | 110 | }) |
| 111 | - public CommonResult<String> socialLoginRedirect(@RequestParam("type") Integer type, | |
| 111 | + public CommonResult<String> socialAuthRedirect(@RequestParam("type") Integer type, | |
| 112 | 112 | @RequestParam("redirectUri") String redirectUri) { |
| 113 | 113 | return CommonResult.success(socialService.getAuthorizeUrl(type, redirectUri)); |
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | @PostMapping("/social-login") |
| 117 | - @ApiOperation("社交登陆,使用 code 授权码") | |
| 117 | + @ApiOperation("社交登录,使用 code 授权码") | |
| 118 | 118 | @OperateLog(enable = false) // 避免 Post 请求被记录操作日志 |
| 119 | 119 | public CommonResult<SysAuthLoginRespVO> socialLogin(@RequestBody @Valid SysAuthSocialLoginReqVO reqVO) { |
| 120 | 120 | String token = authService.socialLogin(reqVO, getClientIP(), getUserAgent()); |
| ... | ... | @@ -123,7 +123,7 @@ public class SysAuthController { |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | @PostMapping("/social-login2") |
| 126 | - @ApiOperation("社交登陆,使用 code 授权码 + 账号密码") | |
| 126 | + @ApiOperation("社交登录,使用 code 授权码 + 账号密码") | |
| 127 | 127 | @OperateLog(enable = false) // 避免 Post 请求被记录操作日志 |
| 128 | 128 | public CommonResult<SysAuthLoginRespVO> socialLogin2(@RequestBody @Valid SysAuthSocialLogin2ReqVO reqVO) { |
| 129 | 129 | String token = authService.socialLogin2(reqVO, getClientIP(), getUserAgent()); |
| ... | ... | @@ -131,4 +131,18 @@ public class SysAuthController { |
| 131 | 131 | return success(SysAuthLoginRespVO.builder().token(token).build()); |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | + @PostMapping("/social-bind") | |
| 135 | + @ApiOperation("社交绑定,使用 code 授权码") | |
| 136 | + public CommonResult<Boolean> socialBind(@RequestBody @Valid SysAuthSocialBindReqVO reqVO) { | |
| 137 | + authService.socialBind(getLoginUserId(), reqVO); | |
| 138 | + return CommonResult.success(true); | |
| 139 | + } | |
| 140 | + | |
| 141 | + @DeleteMapping("/social-unbind") | |
| 142 | + @ApiOperation("取消社交绑定") | |
| 143 | + public CommonResult<Boolean> socialUnbind(@RequestBody SysAuthSocialUnbindReqVO reqVO) { | |
| 144 | + socialService.unbindSocialUser(getLoginUserId(), reqVO.getType(), reqVO.getUnionId()); | |
| 145 | + return CommonResult.success(true); | |
| 146 | + } | |
| 147 | + | |
| 134 | 148 | } | ... | ... |
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; |
| 11 | 11 | import javax.validation.constraints.NotEmpty; |
| 12 | 12 | import javax.validation.constraints.Pattern; |
| 13 | 13 | |
| 14 | -@ApiModel("账号密码登陆 Request VO") | |
| 14 | +@ApiModel("账号密码登录 Request VO") | |
| 15 | 15 | @Data |
| 16 | 16 | @NoArgsConstructor |
| 17 | 17 | @AllArgsConstructor |
| ... | ... | @@ -19,7 +19,7 @@ import javax.validation.constraints.Pattern; |
| 19 | 19 | public class SysAuthLoginReqVO { |
| 20 | 20 | |
| 21 | 21 | @ApiModelProperty(value = "账号", required = true, example = "yudaoyuanma") |
| 22 | - @NotEmpty(message = "登陆账号不能为空") | |
| 22 | + @NotEmpty(message = "登录账号不能为空") | |
| 23 | 23 | @Length(min = 4, max = 16, message = "账号长度为 4-16 位") |
| 24 | 24 | @Pattern(regexp = "^[A-Za-z0-9]+$", message = "账号格式为数字以及字母") |
| 25 | 25 | private String username; | ... | ... |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/auth/vo/auth/SysAuthLoginRespVO.java
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/auth/vo/auth/SysAuthMenuRespVO.java
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; |
| 9 | 9 | |
| 10 | 10 | import java.util.Set; |
| 11 | 11 | |
| 12 | -@ApiModel(value = "登陆用户的权限信息 Response VO", description = "额外包括用户信息和角色列表") | |
| 12 | +@ApiModel(value = "登录用户的权限信息 Response VO", description = "额外包括用户信息和角色列表") | |
| 13 | 13 | @Data |
| 14 | 14 | @NoArgsConstructor |
| 15 | 15 | @AllArgsConstructor | ... | ... |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/auth/vo/auth/SysAuthSocialBindReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.auth; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.adminserver.modules.system.enums.user.SysSocialTypeEnum; | |
| 4 | +import cn.iocoder.yudao.framework.common.validation.InEnum; | |
| 5 | +import io.swagger.annotations.ApiModel; | |
| 6 | +import io.swagger.annotations.ApiModelProperty; | |
| 7 | +import lombok.AllArgsConstructor; | |
| 8 | +import lombok.Builder; | |
| 9 | +import lombok.Data; | |
| 10 | +import lombok.NoArgsConstructor; | |
| 11 | + | |
| 12 | +import javax.validation.constraints.NotEmpty; | |
| 13 | +import javax.validation.constraints.NotNull; | |
| 14 | + | |
| 15 | +@ApiModel("社交绑定 Request VO,使用 code 授权码") | |
| 16 | +@Data | |
| 17 | +@NoArgsConstructor | |
| 18 | +@AllArgsConstructor | |
| 19 | +@Builder | |
| 20 | +public class SysAuthSocialBindReqVO { | |
| 21 | + | |
| 22 | + @ApiModelProperty(value = "社交平台的类型", required = true, example = "10", notes = "参见 SysUserSocialTypeEnum 枚举值") | |
| 23 | + @InEnum(SysSocialTypeEnum.class) | |
| 24 | + @NotNull(message = "社交平台的类型不能为空") | |
| 25 | + private Integer type; | |
| 26 | + | |
| 27 | + @ApiModelProperty(value = "授权码", required = true, example = "1024") | |
| 28 | + @NotEmpty(message = "授权码不能为空") | |
| 29 | + private String code; | |
| 30 | + | |
| 31 | + @ApiModelProperty(value = "state", required = true, example = "9b2ffbc1-7425-4155-9894-9d5c08541d62") | |
| 32 | + @NotEmpty(message = "state 不能为空") | |
| 33 | + private String state; | |
| 34 | + | |
| 35 | +} | ... | ... |
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; |
| 14 | 14 | import javax.validation.constraints.NotNull; |
| 15 | 15 | import javax.validation.constraints.Pattern; |
| 16 | 16 | |
| 17 | -@ApiModel("社交登陆 Request VO,使用 code 授权码 + 账号密码") | |
| 17 | +@ApiModel("社交登录 Request VO,使用 code 授权码 + 账号密码") | |
| 18 | 18 | @Data |
| 19 | 19 | @NoArgsConstructor |
| 20 | 20 | @AllArgsConstructor |
| ... | ... | @@ -35,7 +35,7 @@ public class SysAuthSocialLogin2ReqVO { |
| 35 | 35 | private String state; |
| 36 | 36 | |
| 37 | 37 | @ApiModelProperty(value = "账号", required = true, example = "yudaoyuanma") |
| 38 | - @NotEmpty(message = "登陆账号不能为空") | |
| 38 | + @NotEmpty(message = "登录账号不能为空") | |
| 39 | 39 | @Length(min = 4, max = 16, message = "账号长度为 4-16 位") |
| 40 | 40 | @Pattern(regexp = "^[A-Za-z0-9]+$", message = "账号格式为数字以及字母") |
| 41 | 41 | private String username; | ... | ... |
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; |
| 12 | 12 | import javax.validation.constraints.NotEmpty; |
| 13 | 13 | import javax.validation.constraints.NotNull; |
| 14 | 14 | |
| 15 | -@ApiModel("社交登陆 Request VO,使用 code 授权码") | |
| 15 | +@ApiModel("社交登录 Request VO,使用 code 授权码") | |
| 16 | 16 | @Data |
| 17 | 17 | @NoArgsConstructor |
| 18 | 18 | @AllArgsConstructor | ... | ... |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/auth/vo/auth/SysAuthSocialUnbindReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.auth; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.adminserver.modules.system.enums.user.SysSocialTypeEnum; | |
| 4 | +import cn.iocoder.yudao.framework.common.validation.InEnum; | |
| 5 | +import io.swagger.annotations.ApiModel; | |
| 6 | +import io.swagger.annotations.ApiModelProperty; | |
| 7 | +import lombok.AllArgsConstructor; | |
| 8 | +import lombok.Builder; | |
| 9 | +import lombok.Data; | |
| 10 | +import lombok.NoArgsConstructor; | |
| 11 | + | |
| 12 | +import javax.validation.constraints.NotEmpty; | |
| 13 | +import javax.validation.constraints.NotNull; | |
| 14 | + | |
| 15 | +@ApiModel("取消社交绑定 Request VO,使用 code 授权码") | |
| 16 | +@Data | |
| 17 | +@NoArgsConstructor | |
| 18 | +@AllArgsConstructor | |
| 19 | +@Builder | |
| 20 | +public class SysAuthSocialUnbindReqVO { | |
| 21 | + | |
| 22 | + @ApiModelProperty(value = "社交平台的类型", required = true, example = "10", notes = "参见 SysUserSocialTypeEnum 枚举值") | |
| 23 | + @InEnum(SysSocialTypeEnum.class) | |
| 24 | + @NotNull(message = "社交平台的类型不能为空") | |
| 25 | + private Integer type; | |
| 26 | + | |
| 27 | + @ApiModelProperty(value = "社交的全局编号", required = true, example = "IPRmJ0wvBptiPIlGEZiPewGwiEiE") | |
| 28 | + @NotEmpty(message = "社交的全局编号不能为空") | |
| 29 | + private String unionId; | |
| 30 | + | |
| 31 | +} | ... | ... |
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 { |
| 26 | 26 | @ApiModelProperty(value = "浏览器 UserAgent", required = true, example = "Mozilla/5.0") |
| 27 | 27 | private String userAgent; |
| 28 | 28 | |
| 29 | - @ApiModelProperty(value = "登陆时间", required = true) | |
| 29 | + @ApiModelProperty(value = "登录时间", required = true) | |
| 30 | 30 | private Date createTime; |
| 31 | 31 | |
| 32 | 32 | @ApiModelProperty(value = "用户账号", required = true, example = "yudao") | ... | ... |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/logger/SysLoginLogController.java
| ... | ... | @@ -27,7 +27,7 @@ import java.util.List; |
| 27 | 27 | |
| 28 | 28 | import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; |
| 29 | 29 | |
| 30 | -@Api(tags = "登陆日志") | |
| 30 | +@Api(tags = "登录日志") | |
| 31 | 31 | @RestController |
| 32 | 32 | @RequestMapping("/system/login-log") |
| 33 | 33 | @Validated |
| ... | ... | @@ -37,7 +37,7 @@ public class SysLoginLogController { |
| 37 | 37 | private SysLoginLogService loginLogService; |
| 38 | 38 | |
| 39 | 39 | @GetMapping("/page") |
| 40 | - @ApiOperation("获得登陆日志分页列表") | |
| 40 | + @ApiOperation("获得登录日志分页列表") | |
| 41 | 41 | @PreAuthorize("@ss.hasPermission('system:login-log:query')") |
| 42 | 42 | public CommonResult<PageResult<SysLoginLogRespVO>> getLoginLogPage(@Valid SysLoginLogPageReqVO reqVO) { |
| 43 | 43 | PageResult<SysLoginLogDO> page = loginLogService.getLoginLogPage(reqVO); |
| ... | ... | @@ -45,7 +45,7 @@ public class SysLoginLogController { |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | @GetMapping("/export") |
| 48 | - @ApiOperation("导出登陆日志 Excel") | |
| 48 | + @ApiOperation("导出登录日志 Excel") | |
| 49 | 49 | @PreAuthorize("@ss.hasPermission('system:login-log:export')") |
| 50 | 50 | @OperateLog(type = EXPORT) |
| 51 | 51 | public void exportLoginLog(HttpServletResponse response, @Valid SysLoginLogExportReqVO reqVO) throws IOException { |
| ... | ... | @@ -53,7 +53,7 @@ public class SysLoginLogController { |
| 53 | 53 | // 拼接数据 |
| 54 | 54 | List<SysLoginLogExcelVO> data = SysLoginLogConvert.INSTANCE.convertList(list); |
| 55 | 55 | // 输出 |
| 56 | - ExcelUtils.write(response, "登陆日志.xls", "数据列表", SysLoginLogExcelVO.class, data); | |
| 56 | + ExcelUtils.write(response, "登录日志.xls", "数据列表", SysLoginLogExcelVO.class, data); | |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | } | ... | ... |
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; |
| 9 | 9 | import javax.validation.constraints.Size; |
| 10 | 10 | |
| 11 | 11 | /** |
| 12 | - * 登陆日志 Base VO,提供给添加、修改、详细的子 VO 使用 | |
| 12 | + * 登录日志 Base VO,提供给添加、修改、详细的子 VO 使用 | |
| 13 | 13 | * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 |
| 14 | 14 | */ |
| 15 | 15 | @Data |
| ... | ... | @@ -28,8 +28,8 @@ public class SysLoginLogBaseVO { |
| 28 | 28 | @Size(max = 30, message = "用户账号长度不能超过30个字符") |
| 29 | 29 | private String username; |
| 30 | 30 | |
| 31 | - @ApiModelProperty(value = "登陆结果", required = true, example = "1", notes = "参见 SysLoginResultEnum 枚举类") | |
| 32 | - @NotNull(message = "登陆结果不能为空") | |
| 31 | + @ApiModelProperty(value = "登录结果", required = true, example = "1", notes = "参见 SysLoginResultEnum 枚举类") | |
| 32 | + @NotNull(message = "登录结果不能为空") | |
| 33 | 33 | private Integer result; |
| 34 | 34 | |
| 35 | 35 | @ApiModelProperty(value = "用户 IP", required = true, example = "127.0.0.1") | ... | ... |
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; |
| 5 | 5 | import lombok.EqualsAndHashCode; |
| 6 | 6 | import lombok.ToString; |
| 7 | 7 | |
| 8 | -@ApiModel(value = "登陆日志创建 Request VO", | |
| 9 | - description = "暂时提供给前端,仅仅后端记录登陆日志时,进行使用") | |
| 8 | +@ApiModel(value = "登录日志创建 Request VO", | |
| 9 | + description = "暂时提供给前端,仅仅后端记录登录日志时,进行使用") | |
| 10 | 10 | @Data |
| 11 | 11 | @EqualsAndHashCode(callSuper = true) |
| 12 | 12 | @ToString(callSuper = true) | ... | ... |
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; |
| 9 | 9 | import java.util.Date; |
| 10 | 10 | |
| 11 | 11 | /** |
| 12 | - * 登陆日志 Excel 导出响应 VO | |
| 12 | + * 登录日志 Excel 导出响应 VO | |
| 13 | 13 | */ |
| 14 | 14 | @Data |
| 15 | 15 | public class SysLoginLogExcelVO { |
| ... | ... | @@ -24,17 +24,17 @@ public class SysLoginLogExcelVO { |
| 24 | 24 | @DictFormat(SysDictTypeConstants.LOGIN_TYPE) |
| 25 | 25 | private Integer logType; |
| 26 | 26 | |
| 27 | - @ExcelProperty(value = "登陆结果", converter = DictConvert.class) | |
| 27 | + @ExcelProperty(value = "登录结果", converter = DictConvert.class) | |
| 28 | 28 | @DictFormat(SysDictTypeConstants.LOGIN_RESULT) |
| 29 | 29 | private Integer result; |
| 30 | 30 | |
| 31 | - @ExcelProperty("登陆 IP") | |
| 31 | + @ExcelProperty("登录 IP") | |
| 32 | 32 | private String userIp; |
| 33 | 33 | |
| 34 | 34 | @ExcelProperty("浏览器 UA") |
| 35 | 35 | private String userAgent; |
| 36 | 36 | |
| 37 | - @ExcelProperty("登陆时间") | |
| 37 | + @ExcelProperty("登录时间") | |
| 38 | 38 | private Date createTime; |
| 39 | 39 | |
| 40 | 40 | } | ... | ... |
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; |
| 9 | 9 | |
| 10 | 10 | import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; |
| 11 | 11 | |
| 12 | -@ApiModel("登陆日志分页列表 Request VO") | |
| 12 | +@ApiModel("登录日志分页列表 Request VO") | |
| 13 | 13 | @Data |
| 14 | 14 | public class SysLoginLogExportReqVO { |
| 15 | 15 | ... | ... |
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; |
| 11 | 11 | |
| 12 | 12 | import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; |
| 13 | 13 | |
| 14 | -@ApiModel("登陆日志分页列表 Request VO") | |
| 14 | +@ApiModel("登录日志分页列表 Request VO") | |
| 15 | 15 | @Data |
| 16 | 16 | @EqualsAndHashCode(callSuper = true) |
| 17 | 17 | public class SysLoginLogPageReqVO extends PageParam { | ... | ... |
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; |
| 9 | 9 | import javax.validation.constraints.NotNull; |
| 10 | 10 | import java.util.Date; |
| 11 | 11 | |
| 12 | -@ApiModel("登陆日志 Response VO") | |
| 12 | +@ApiModel("登录日志 Response VO") | |
| 13 | 13 | @Data |
| 14 | 14 | @EqualsAndHashCode(callSuper = true) |
| 15 | 15 | @ToString(callSuper = true) |
| ... | ... | @@ -26,7 +26,7 @@ public class SysLoginLogRespVO extends SysLoginLogBaseVO { |
| 26 | 26 | @NotNull(message = "用户类型不能为空") |
| 27 | 27 | private Integer userType; |
| 28 | 28 | |
| 29 | - @ApiModelProperty(value = "登陆时间", required = true) | |
| 29 | + @ApiModelProperty(value = "登录时间", required = true) | |
| 30 | 30 | private Date createTime; |
| 31 | 31 | |
| 32 | 32 | } | ... | ... |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/user/SysUserProfileController.http
0 → 100644
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/user/SysUserProfileController.java
| 1 | 1 | package cn.iocoder.yudao.adminserver.modules.system.controller.user; |
| 2 | 2 | |
| 3 | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | +import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.social.SysSocialUserDO; | |
| 5 | +import cn.iocoder.yudao.adminserver.modules.system.service.social.SysSocialService; | |
| 4 | 6 | import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil; |
| 5 | 7 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 6 | 8 | import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.profile.SysUserProfileRespVO; |
| ... | ... | @@ -52,6 +54,8 @@ public class SysUserProfileController { |
| 52 | 54 | private SysPermissionService permissionService; |
| 53 | 55 | @Resource |
| 54 | 56 | private SysRoleService roleService; |
| 57 | + @Resource | |
| 58 | + private SysSocialService socialService; | |
| 55 | 59 | |
| 56 | 60 | @GetMapping("/get") |
| 57 | 61 | @ApiOperation("获得登录用户信息") |
| ... | ... | @@ -72,6 +76,9 @@ public class SysUserProfileController { |
| 72 | 76 | List<SysPostDO> posts = postService.getPosts(user.getPostIds()); |
| 73 | 77 | resp.setPosts(SysUserConvert.INSTANCE.convertList02(posts)); |
| 74 | 78 | } |
| 79 | + // 获得社交用户信息 | |
| 80 | + List<SysSocialUserDO> socialUsers = socialService.getSocialUserList(user.getId()); | |
| 81 | + resp.setSocialUsers(SysUserConvert.INSTANCE.convertList03(socialUsers)); | |
| 75 | 82 | return success(resp); |
| 76 | 83 | } |
| 77 | 84 | ... | ... |
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 { |
| 25 | 25 | @ApiModelProperty(value = "状态", required = true, example = "1", notes = "参见 SysCommonStatusEnum 枚举类") |
| 26 | 26 | private Integer status; |
| 27 | 27 | |
| 28 | - @ApiModelProperty(value = "最后登陆 IP", required = true, example = "192.168.1.1") | |
| 28 | + @ApiModelProperty(value = "最后登录 IP", required = true, example = "192.168.1.1") | |
| 29 | 29 | private String loginIp; |
| 30 | 30 | |
| 31 | 31 | @ApiModelProperty(value = "最后登录时间", required = true, example = "时间戳格式") |
| ... | ... | @@ -48,6 +48,10 @@ public class SysUserProfileRespVO extends SysUserBaseVO { |
| 48 | 48 | * 所属岗位数组 |
| 49 | 49 | */ |
| 50 | 50 | private List<Post> posts; |
| 51 | + /** | |
| 52 | + * 社交用户数组 | |
| 53 | + */ | |
| 54 | + private List<SocialUser> socialUsers; | |
| 51 | 55 | |
| 52 | 56 | @ApiModel("角色") |
| 53 | 57 | @Data |
| ... | ... | @@ -85,4 +89,16 @@ public class SysUserProfileRespVO extends SysUserBaseVO { |
| 85 | 89 | |
| 86 | 90 | } |
| 87 | 91 | |
| 92 | + @ApiModel("社交用户") | |
| 93 | + @Data | |
| 94 | + public static class SocialUser { | |
| 95 | + | |
| 96 | + @ApiModelProperty(value = "社交平台的类型", required = true, example = "10", notes = "参见 SysSocialTypeEnum 枚举类") | |
| 97 | + private Integer type; | |
| 98 | + | |
| 99 | + @ApiModelProperty(value = "社交的全局编号", required = true, example = "IPRmJ0wvBptiPIlGEZiPewGwiEiE") | |
| 100 | + private String unionId; | |
| 101 | + | |
| 102 | + } | |
| 103 | + | |
| 88 | 104 | } | ... | ... |
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 { |
| 19 | 19 | @ApiModelProperty(value = "状态", required = true, example = "1", notes = "参见 SysCommonStatusEnum 枚举类") |
| 20 | 20 | private Integer status; |
| 21 | 21 | |
| 22 | - @ApiModelProperty(value = "最后登陆 IP", required = true, example = "192.168.1.1") | |
| 22 | + @ApiModelProperty(value = "最后登录 IP", required = true, example = "192.168.1.1") | |
| 23 | 23 | private String loginIp; |
| 24 | 24 | |
| 25 | 25 | @ApiModelProperty(value = "最后登录时间", required = true, example = "时间戳格式") | ... | ... |
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.*; |
| 7 | 7 | import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.dept.SysDeptDO; |
| 8 | 8 | import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.dept.SysPostDO; |
| 9 | 9 | import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.permission.SysRoleDO; |
| 10 | +import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.social.SysSocialUserDO; | |
| 10 | 11 | import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.user.SysUserDO; |
| 11 | 12 | import org.mapstruct.Mapper; |
| 12 | 13 | import org.mapstruct.factory.Mappers; |
| ... | ... | @@ -42,4 +43,6 @@ public interface SysUserConvert { |
| 42 | 43 | |
| 43 | 44 | List<SysUserProfileRespVO.Post> convertList02(List<SysPostDO> list); |
| 44 | 45 | |
| 46 | + List<SysUserProfileRespVO.SocialUser> convertList03(List<SysSocialUserDO> list); | |
| 47 | + | |
| 45 | 48 | } | ... | ... |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/dataobject/logger/SysLoginLogDO.java
| ... | ... | @@ -10,9 +10,9 @@ import lombok.EqualsAndHashCode; |
| 10 | 10 | import lombok.ToString; |
| 11 | 11 | |
| 12 | 12 | /** |
| 13 | - * 登陆日志表 | |
| 13 | + * 登录日志表 | |
| 14 | 14 | * |
| 15 | - * 注意,包括登陆和登出两种行为 | |
| 15 | + * 注意,包括登录和登出两种行为 | |
| 16 | 16 | * |
| 17 | 17 | * @author ruoyi |
| 18 | 18 | */ |
| ... | ... | @@ -53,7 +53,7 @@ public class SysLoginLogDO extends BaseDO { |
| 53 | 53 | */ |
| 54 | 54 | private String username; |
| 55 | 55 | /** |
| 56 | - * 登陆结果 | |
| 56 | + * 登录结果 | |
| 57 | 57 | * |
| 58 | 58 | * 枚举 {@link SysLoginResultEnum} |
| 59 | 59 | */ | ... | ... |
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<SysSocialUserDO> { |
| 21 | 21 | .in("type", types).eq("user_id", userId)); |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | + default List<SysSocialUserDO> selectListByUserId(Integer userType, Long userId) { | |
| 25 | + return selectList(new QueryWrapper<SysSocialUserDO>().eq("user_type", userType).eq("user_id", userId)); | |
| 26 | + } | |
| 27 | + | |
| 24 | 28 | } | ... | ... |
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 |
| 15 | 15 | */ |
| 16 | 16 | public interface SysRedisKeyConstants { |
| 17 | 17 | |
| 18 | - RedisKeyDefine LOGIN_USER = new RedisKeyDefine("登陆用户的缓存", | |
| 18 | + RedisKeyDefine LOGIN_USER = new RedisKeyDefine("登录用户的缓存", | |
| 19 | 19 | "login_user:%s", // 参数为 sessionId |
| 20 | 20 | STRING, LoginUser.class, RedisKeyDefine.TimeoutTypeEnum.DYNAMIC); |
| 21 | 21 | ... | ... |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/enums/SysDictTypeConstants.java
| ... | ... | @@ -12,8 +12,8 @@ public interface SysDictTypeConstants { |
| 12 | 12 | |
| 13 | 13 | String USER_SEX = "sys_user_sex"; // 用户性别 |
| 14 | 14 | String OPERATE_TYPE = "sys_operate_type"; // 操作类型 |
| 15 | - String LOGIN_TYPE = "sys_login_type"; // 登陆日志的类型 | |
| 16 | - String LOGIN_RESULT = "sys_login_result"; // 登陆结果 | |
| 15 | + String LOGIN_TYPE = "sys_login_type"; // 登录日志的类型 | |
| 16 | + String LOGIN_RESULT = "sys_login_result"; // 登录结果 | |
| 17 | 17 | String CONFIG_TYPE = "sys_config_type"; // 参数配置类型 |
| 18 | 18 | String BOOLEAN_STRING = "sys_boolean_string"; // Boolean 是否类型 |
| 19 | 19 | ... | ... |
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; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.adminserver.modules.tool.framework.errorcode.config.ErrorCodeConfiguration; |
| 4 | 4 | import cn.iocoder.yudao.framework.common.exception.ErrorCode; |
| 5 | +import org.springframework.validation.Errors; | |
| 5 | 6 | |
| 6 | 7 | /** |
| 7 | 8 | * System 错误码枚举类 |
| ... | ... | @@ -13,7 +14,7 @@ public interface SysErrorCodeConstants { |
| 13 | 14 | // ========== AUTH 模块 1002000000 ========== |
| 14 | 15 | ErrorCode AUTH_LOGIN_BAD_CREDENTIALS = new ErrorCode(1002000000, "登录失败,账号密码不正确"); |
| 15 | 16 | ErrorCode AUTH_LOGIN_USER_DISABLED = new ErrorCode(1002000001, "登录失败,账号被禁用"); |
| 16 | - ErrorCode AUTH_LOGIN_FAIL_UNKNOWN = new ErrorCode(1002000002, "登录失败"); // 登陆失败的兜底,位置原因 | |
| 17 | + ErrorCode AUTH_LOGIN_FAIL_UNKNOWN = new ErrorCode(1002000002, "登录失败"); // 登录失败的兜底,位置原因 | |
| 17 | 18 | ErrorCode AUTH_LOGIN_CAPTCHA_NOT_FOUND = new ErrorCode(1002000003, "验证码不存在"); |
| 18 | 19 | ErrorCode AUTH_LOGIN_CAPTCHA_CODE_ERROR = new ErrorCode(1002000004, "验证码不正确"); |
| 19 | 20 | ErrorCode AUTH_THIRD_LOGIN_NOT_BIND = new ErrorCode(1002000005, "未绑定账号,需要进行绑定"); |
| ... | ... | @@ -99,5 +100,6 @@ public interface SysErrorCodeConstants { |
| 99 | 100 | |
| 100 | 101 | // ========== 社交模块 1002014000 ========== |
| 101 | 102 | ErrorCode SOCIAL_AUTH_FAILURE = new ErrorCode(1002014000, "社交授权失败,原因是:{}"); |
| 103 | + ErrorCode SOCIAL_UNBIND_NOT_SELF = new ErrorCode(1002014001, "社交解绑失败,非当前用户绑定"); | |
| 102 | 104 | |
| 103 | 105 | } | ... | ... |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/enums/logger/SysLoginLogTypeEnum.java
| ... | ... | @@ -4,15 +4,15 @@ import lombok.AllArgsConstructor; |
| 4 | 4 | import lombok.Getter; |
| 5 | 5 | |
| 6 | 6 | /** |
| 7 | - * 登陆日志的类型枚举 | |
| 7 | + * 登录日志的类型枚举 | |
| 8 | 8 | */ |
| 9 | 9 | @Getter |
| 10 | 10 | @AllArgsConstructor |
| 11 | 11 | public enum SysLoginLogTypeEnum { |
| 12 | 12 | |
| 13 | 13 | LOGIN_USERNAME(100), // 使用账号登录 |
| 14 | - LOGIN_SOCIAL(101), // 使用社交登陆 | |
| 15 | - LOGIN_MOCK(102), // 使用 Mock 登陆 | |
| 14 | + LOGIN_SOCIAL(101), // 使用社交登录 | |
| 15 | + LOGIN_MOCK(102), // 使用 Mock 登录 | |
| 16 | 16 | |
| 17 | 17 | LOGOUT_SELF(200), // 自己主动登出 |
| 18 | 18 | LOGOUT_TIMEOUT(201), // 超时登出 | ... | ... |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/enums/logger/SysLoginResultEnum.java
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/auth/SysAuthService.java
| 1 | 1 | package cn.iocoder.yudao.adminserver.modules.system.service.auth; |
| 2 | 2 | |
| 3 | -import cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.auth.SysAuthSocialLogin2ReqVO; | |
| 4 | -import cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.auth.SysAuthSocialLoginReqVO; | |
| 3 | +import cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.auth.*; | |
| 5 | 4 | import cn.iocoder.yudao.framework.security.core.service.SecurityAuthFrameworkService; |
| 6 | -import cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.auth.SysAuthLoginReqVO; | |
| 5 | + | |
| 6 | +import javax.validation.Valid; | |
| 7 | 7 | |
| 8 | 8 | /** |
| 9 | 9 | * 认证 Service 接口 |
| 10 | 10 | * |
| 11 | - * 提供用户的账号密码登陆、token 的校验等认证相关的功能 | |
| 11 | + * 提供用户的账号密码登录、token 的校验等认证相关的功能 | |
| 12 | 12 | * |
| 13 | 13 | * @author 芋道源码 |
| 14 | 14 | */ |
| 15 | 15 | public interface SysAuthService extends SecurityAuthFrameworkService { |
| 16 | 16 | |
| 17 | 17 | /** |
| 18 | - * 登陆用户 | |
| 18 | + * 账号登录 | |
| 19 | 19 | * |
| 20 | - * @param reqVO 登陆信息 | |
| 20 | + * @param reqVO 登录信息 | |
| 21 | 21 | * @param userIp 用户 IP |
| 22 | 22 | * @param userAgent 用户 UA |
| 23 | 23 | * @return 身份令牌,使用 JWT 方式 |
| 24 | 24 | */ |
| 25 | - String login(SysAuthLoginReqVO reqVO, String userIp, String userAgent); | |
| 25 | + String login(@Valid SysAuthLoginReqVO reqVO, String userIp, String userAgent); | |
| 26 | 26 | |
| 27 | 27 | /** |
| 28 | - * 社交登陆用户,使用 code 授权码 | |
| 28 | + * 社交登录,使用 code 授权码 | |
| 29 | 29 | * |
| 30 | - * @param reqVO 登陆信息 | |
| 30 | + * @param reqVO 登录信息 | |
| 31 | 31 | * @param userIp 用户 IP |
| 32 | 32 | * @param userAgent 用户 UA |
| 33 | 33 | * @return 身份令牌,使用 JWT 方式 |
| 34 | 34 | */ |
| 35 | - String socialLogin(SysAuthSocialLoginReqVO reqVO, String userIp, String userAgent); | |
| 35 | + String socialLogin(@Valid SysAuthSocialLoginReqVO reqVO, String userIp, String userAgent); | |
| 36 | 36 | |
| 37 | 37 | /** |
| 38 | - * 社交登陆用户,使用 code 授权码 + 账号密码 | |
| 38 | + * 社交登录,使用 code 授权码 + 账号密码 | |
| 39 | 39 | * |
| 40 | - * @param reqVO 登陆信息 | |
| 40 | + * @param reqVO 登录信息 | |
| 41 | 41 | * @param userIp 用户 IP |
| 42 | 42 | * @param userAgent 用户 UA |
| 43 | 43 | * @return 身份令牌,使用 JWT 方式 |
| 44 | 44 | */ |
| 45 | - String socialLogin2(SysAuthSocialLogin2ReqVO reqVO, String userIp, String userAgent); | |
| 45 | + String socialLogin2(@Valid SysAuthSocialLogin2ReqVO reqVO, String userIp, String userAgent); | |
| 46 | + | |
| 47 | + /** | |
| 48 | + * 社交绑定,使用 code 授权码 | |
| 49 | + * | |
| 50 | + * @param userId 用户编号 | |
| 51 | + * @param reqVO 绑定信息 | |
| 52 | + */ | |
| 53 | + void socialBind(Long userId, @Valid SysAuthSocialBindReqVO reqVO); | |
| 46 | 54 | |
| 47 | 55 | } | ... | ... |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/auth/SysUserSessionService.java
| ... | ... | @@ -15,7 +15,7 @@ public interface SysUserSessionService { |
| 15 | 15 | /** |
| 16 | 16 | * 创建在线用户 Session |
| 17 | 17 | * |
| 18 | - * @param loginUser 登陆用户 | |
| 18 | + * @param loginUser 登录用户 | |
| 19 | 19 | * @param userIp 用户 IP |
| 20 | 20 | * @param userAgent 用户 UA |
| 21 | 21 | * @return Session 编号 |
| ... | ... | @@ -26,7 +26,7 @@ public interface SysUserSessionService { |
| 26 | 26 | * 刷新在线用户 Session 的更新时间 |
| 27 | 27 | * |
| 28 | 28 | * @param sessionId Session 编号 |
| 29 | - * @param loginUser 登陆用户 | |
| 29 | + * @param loginUser 登录用户 | |
| 30 | 30 | */ |
| 31 | 31 | void refreshUserSession(String sessionId, LoginUser loginUser); |
| 32 | 32 | ... | ... |
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; |
| 2 | 2 | |
| 3 | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | 4 | import cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.auth.SysAuthLoginReqVO; |
| 5 | +import cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.auth.SysAuthSocialBindReqVO; | |
| 5 | 6 | import cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.auth.SysAuthSocialLogin2ReqVO; |
| 6 | 7 | import cn.iocoder.yudao.adminserver.modules.system.controller.auth.vo.auth.SysAuthSocialLoginReqVO; |
| 7 | 8 | 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 |
| 18 | 19 | import cn.iocoder.yudao.adminserver.modules.system.service.social.SysSocialService; |
| 19 | 20 | import cn.iocoder.yudao.adminserver.modules.system.service.user.SysUserService; |
| 20 | 21 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 21 | -import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil; | |
| 22 | 22 | import cn.iocoder.yudao.framework.common.util.monitor.TracerUtils; |
| 23 | 23 | import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils; |
| 24 | 24 | import cn.iocoder.yudao.framework.security.core.LoginUser; |
| ... | ... | @@ -101,11 +101,11 @@ public class SysAuthServiceImpl implements SysAuthService { |
| 101 | 101 | // 判断验证码是否正确 |
| 102 | 102 | this.verifyCaptcha(reqVO.getUsername(), reqVO.getUuid(), reqVO.getCode()); |
| 103 | 103 | |
| 104 | - // 使用账号密码,进行登陆。 | |
| 104 | + // 使用账号密码,进行登录。 | |
| 105 | 105 | LoginUser loginUser = this.login0(reqVO.getUsername(), reqVO.getPassword()); |
| 106 | 106 | loginUser.setRoleIds(this.getUserRoleIds(loginUser.getId())); // 获取用户角色列表 |
| 107 | 107 | |
| 108 | - // 缓存登陆用户到 Redis 中,返回 sessionId 编号 | |
| 108 | + // 缓存登录用户到 Redis 中,返回 sessionId 编号 | |
| 109 | 109 | return userSessionService.createUserSession(loginUser, userIp, userAgent); |
| 110 | 110 | } |
| 111 | 111 | |
| ... | ... | @@ -114,13 +114,13 @@ public class SysAuthServiceImpl implements SysAuthService { |
| 114 | 114 | String code = captchaService.getCaptchaCode(captchaUUID); |
| 115 | 115 | // 验证码不存在 |
| 116 | 116 | if (code == null) { |
| 117 | - // 创建登陆失败日志(验证码不存在) | |
| 117 | + // 创建登录失败日志(验证码不存在) | |
| 118 | 118 | this.createLoginLog(username, logTypeEnum, SysLoginResultEnum.CAPTCHA_NOT_FOUND); |
| 119 | 119 | throw exception(AUTH_LOGIN_CAPTCHA_NOT_FOUND); |
| 120 | 120 | } |
| 121 | 121 | // 验证码不正确 |
| 122 | 122 | if (!code.equals(captchaCode)) { |
| 123 | - // 创建登陆失败日志(验证码不正确) | |
| 123 | + // 创建登录失败日志(验证码不正确) | |
| 124 | 124 | this.createLoginLog(username, logTypeEnum, SysLoginResultEnum.CAPTCHA_CODE_ERROR); |
| 125 | 125 | throw exception(AUTH_LOGIN_CAPTCHA_CODE_ERROR); |
| 126 | 126 | } |
| ... | ... | @@ -147,7 +147,7 @@ public class SysAuthServiceImpl implements SysAuthService { |
| 147 | 147 | this.createLoginLog(username, logTypeEnum, SysLoginResultEnum.UNKNOWN_ERROR); |
| 148 | 148 | throw exception(AUTH_LOGIN_FAIL_UNKNOWN); |
| 149 | 149 | } |
| 150 | - // 登陆成功的日志 | |
| 150 | + // 登录成功的日志 | |
| 151 | 151 | Assert.notNull(authentication.getPrincipal(), "Principal 不会为空"); |
| 152 | 152 | this.createLoginLog(username, logTypeEnum, SysLoginResultEnum.SUCCESS); |
| 153 | 153 | return (LoginUser) authentication.getPrincipal(); |
| ... | ... | @@ -176,18 +176,18 @@ public class SysAuthServiceImpl implements SysAuthService { |
| 176 | 176 | |
| 177 | 177 | @Override |
| 178 | 178 | public String socialLogin(SysAuthSocialLoginReqVO reqVO, String userIp, String userAgent) { |
| 179 | - // 使用 code 授权码,进行登陆 | |
| 179 | + // 使用 code 授权码,进行登录 | |
| 180 | 180 | AuthUser authUser = socialService.getAuthUser(reqVO.getType(), reqVO.getCode(), reqVO.getState()); |
| 181 | 181 | Assert.notNull(authUser, "授权用户不为空"); |
| 182 | 182 | |
| 183 | - // 如果未绑定 SysSocialUserDO 用户,则无法自动登陆,进行报错 | |
| 183 | + // 如果未绑定 SysSocialUserDO 用户,则无法自动登录,进行报错 | |
| 184 | 184 | String unionId = socialService.getAuthUserUnionId(authUser); |
| 185 | 185 | List<SysSocialUserDO> socialUsers = socialService.getAllSocialUserList(reqVO.getType(), unionId); |
| 186 | 186 | if (CollUtil.isEmpty(socialUsers)) { |
| 187 | 187 | throw exception(AUTH_THIRD_LOGIN_NOT_BIND); |
| 188 | 188 | } |
| 189 | 189 | |
| 190 | - // 自动登陆 | |
| 190 | + // 自动登录 | |
| 191 | 191 | SysUserDO user = userService.getUser(socialUsers.get(0).getUserId()); |
| 192 | 192 | if (user == null) { |
| 193 | 193 | throw exception(USER_NOT_EXISTS); |
| ... | ... | @@ -196,34 +196,44 @@ public class SysAuthServiceImpl implements SysAuthService { |
| 196 | 196 | |
| 197 | 197 | // 创建 LoginUser 对象 |
| 198 | 198 | LoginUser loginUser = SysAuthConvert.INSTANCE.convert(user); |
| 199 | - // TODO 芋艿:需要改造下,增加各种登陆方式 | |
| 199 | + // TODO 芋艿:需要改造下,增加各种登录方式 | |
| 200 | 200 | loginUser.setRoleIds(this.getUserRoleIds(loginUser.getId())); // 获取用户角色列表 |
| 201 | 201 | |
| 202 | 202 | // 绑定社交用户(更新) |
| 203 | 203 | socialService.bindSocialUser(loginUser.getId(), reqVO.getType(), authUser); |
| 204 | 204 | |
| 205 | - // 缓存登陆用户到 Redis 中,返回 sessionId 编号 | |
| 205 | + // 缓存登录用户到 Redis 中,返回 sessionId 编号 | |
| 206 | 206 | return userSessionService.createUserSession(loginUser, userIp, userAgent); |
| 207 | 207 | } |
| 208 | 208 | |
| 209 | 209 | @Override |
| 210 | 210 | public String socialLogin2(SysAuthSocialLogin2ReqVO reqVO, String userIp, String userAgent) { |
| 211 | - // 使用 code 授权码,进行登陆 | |
| 211 | + // 使用 code 授权码,进行登录 | |
| 212 | 212 | AuthUser authUser = socialService.getAuthUser(reqVO.getType(), reqVO.getCode(), reqVO.getState()); |
| 213 | 213 | Assert.notNull(authUser, "授权用户不为空"); |
| 214 | 214 | |
| 215 | - // 使用账号密码,进行登陆。 | |
| 215 | + // 使用账号密码,进行登录。 | |
| 216 | 216 | LoginUser loginUser = this.login0(reqVO.getUsername(), reqVO.getPassword()); |
| 217 | 217 | loginUser.setRoleIds(this.getUserRoleIds(loginUser.getId())); // 获取用户角色列表 |
| 218 | 218 | |
| 219 | 219 | // 绑定社交用户(新增) |
| 220 | 220 | socialService.bindSocialUser(loginUser.getId(), reqVO.getType(), authUser); |
| 221 | 221 | |
| 222 | - // 缓存登陆用户到 Redis 中,返回 sessionId 编号 | |
| 222 | + // 缓存登录用户到 Redis 中,返回 sessionId 编号 | |
| 223 | 223 | return userSessionService.createUserSession(loginUser, userIp, userAgent); |
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | @Override |
| 227 | + public void socialBind(Long userId, SysAuthSocialBindReqVO reqVO) { | |
| 228 | + // 使用 code 授权码,进行登录 | |
| 229 | + AuthUser authUser = socialService.getAuthUser(reqVO.getType(), reqVO.getCode(), reqVO.getState()); | |
| 230 | + Assert.notNull(authUser, "授权用户不为空"); | |
| 231 | + | |
| 232 | + // 绑定社交用户(新增) | |
| 233 | + socialService.bindSocialUser(userId, reqVO.getType(), authUser); | |
| 234 | + } | |
| 235 | + | |
| 236 | + @Override | |
| 227 | 237 | public void logout(String token) { |
| 228 | 238 | // 查询用户信息 |
| 229 | 239 | LoginUser loginUser = userSessionService.getLoginUser(token); |
| ... | ... | @@ -269,7 +279,7 @@ public class SysAuthServiceImpl implements SysAuthService { |
| 269 | 279 | // 重新加载 SysUserDO 信息 |
| 270 | 280 | SysUserDO user = userService.getUser(loginUser.getId()); |
| 271 | 281 | if (user == null || CommonStatusEnum.DISABLE.getStatus().equals(user.getStatus())) { |
| 272 | - throw exception(TOKEN_EXPIRED); // 校验 token 时,用户被禁用的情况下,也认为 token 过期,方便前端跳转到登陆界面 | |
| 282 | + throw exception(TOKEN_EXPIRED); // 校验 token 时,用户被禁用的情况下,也认为 token 过期,方便前端跳转到登录界面 | |
| 273 | 283 | } |
| 274 | 284 | |
| 275 | 285 | // 刷新 LoginUser 缓存 | ... | ... |
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 |
| 9 | 9 | import java.util.List; |
| 10 | 10 | |
| 11 | 11 | /** |
| 12 | - * 登陆日志 Service 接口 | |
| 12 | + * 登录日志 Service 接口 | |
| 13 | 13 | */ |
| 14 | 14 | public interface SysLoginLogService { |
| 15 | 15 | |
| 16 | 16 | /** |
| 17 | - * 创建登陆日志 | |
| 17 | + * 创建登录日志 | |
| 18 | 18 | * |
| 19 | 19 | * @param reqVO 日志信息 |
| 20 | 20 | */ |
| 21 | 21 | void createLoginLog(SysLoginLogCreateReqVO reqVO); |
| 22 | 22 | |
| 23 | 23 | /** |
| 24 | - * 获得登陆日志分页 | |
| 24 | + * 获得登录日志分页 | |
| 25 | 25 | * |
| 26 | 26 | * @param reqVO 分页条件 |
| 27 | - * @return 登陆日志分页 | |
| 27 | + * @return 登录日志分页 | |
| 28 | 28 | */ |
| 29 | 29 | PageResult<SysLoginLogDO> getLoginLogPage(SysLoginLogPageReqVO reqVO); |
| 30 | 30 | |
| 31 | 31 | /** |
| 32 | - * 获得登陆日志列表 | |
| 32 | + * 获得登录日志列表 | |
| 33 | 33 | * |
| 34 | 34 | * @param reqVO 列表条件 |
| 35 | - * @return 登陆日志列表 | |
| 35 | + * @return 登录日志列表 | |
| 36 | 36 | */ |
| 37 | 37 | List<SysLoginLogDO> getLoginLogList(SysLoginLogExportReqVO reqVO); |
| 38 | 38 | ... | ... |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/logger/impl/SysLoginLogServiceImpl.java
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 { |
| 280 | 280 | return true; |
| 281 | 281 | } |
| 282 | 282 | |
| 283 | - // 获得当前登陆的角色。如果为空,说明没有权限 | |
| 283 | + // 获得当前登录的角色。如果为空,说明没有权限 | |
| 284 | 284 | Set<Long> roleIds = SecurityFrameworkUtils.getLoginUserRoleIds(); |
| 285 | 285 | if (CollUtil.isEmpty(roleIds)) { |
| 286 | 286 | return false; |
| ... | ... | @@ -315,7 +315,7 @@ public class SysPermissionServiceImpl implements SysPermissionService { |
| 315 | 315 | return true; |
| 316 | 316 | } |
| 317 | 317 | |
| 318 | - // 获得当前登陆的角色。如果为空,说明没有权限 | |
| 318 | + // 获得当前登录的角色。如果为空,说明没有权限 | |
| 319 | 319 | Set<Long> roleIds = SecurityFrameworkUtils.getLoginUserRoleIds(); |
| 320 | 320 | if (CollUtil.isEmpty(roleIds)) { |
| 321 | 321 | return false; | ... | ... |
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; |
| 4 | 4 | import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.social.SysSocialUserDO; |
| 5 | 5 | import cn.iocoder.yudao.adminserver.modules.system.enums.user.SysSocialTypeEnum; |
| 6 | 6 | import cn.iocoder.yudao.framework.common.exception.ServiceException; |
| 7 | +import io.swagger.models.auth.In; | |
| 7 | 8 | import me.zhyd.oauth.model.AuthUser; |
| 8 | 9 | |
| 9 | 10 | import javax.validation.constraints.NotNull; |
| ... | ... | @@ -52,6 +53,14 @@ public interface SysSocialService { |
| 52 | 53 | List<SysSocialUserDO> getAllSocialUserList(Integer type, String unionId); |
| 53 | 54 | |
| 54 | 55 | /** |
| 56 | + * 获得指定用户的社交用户列表 | |
| 57 | + * | |
| 58 | + * @param userId 用户编号 | |
| 59 | + * @return 社交用户列表 | |
| 60 | + */ | |
| 61 | + List<SysSocialUserDO> getSocialUserList(Long userId); | |
| 62 | + | |
| 63 | + /** | |
| 55 | 64 | * 绑定社交用户 |
| 56 | 65 | * |
| 57 | 66 | * @param userId 用户编号 |
| ... | ... | @@ -60,4 +69,13 @@ public interface SysSocialService { |
| 60 | 69 | */ |
| 61 | 70 | void bindSocialUser(Long userId, Integer type, AuthUser authUser); |
| 62 | 71 | |
| 72 | + /** | |
| 73 | + * 取消绑定社交用户 | |
| 74 | + * | |
| 75 | + * @param userId 用户编号 | |
| 76 | + * @param type 社交平台的类型 {@link SysSocialTypeEnum} | |
| 77 | + * @param unionId 社交平台的 unionId | |
| 78 | + */ | |
| 79 | + void unbindSocialUser(Long userId, Integer type, String unionId); | |
| 80 | + | |
| 63 | 81 | } | ... | ... |
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 |
| 9 | 9 | import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; |
| 10 | 10 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; |
| 11 | 11 | import cn.iocoder.yudao.framework.common.util.http.HttpUtils; |
| 12 | -import cn.iocoder.yudao.framework.common.util.json.JsonUtils; | |
| 13 | 12 | import com.xkcoding.justauth.AuthRequestFactory; |
| 14 | 13 | import lombok.extern.slf4j.Slf4j; |
| 15 | 14 | import me.zhyd.oauth.model.AuthCallback; |
| ... | ... | @@ -18,15 +17,17 @@ import me.zhyd.oauth.model.AuthUser; |
| 18 | 17 | import me.zhyd.oauth.request.AuthRequest; |
| 19 | 18 | import me.zhyd.oauth.utils.AuthStateUtils; |
| 20 | 19 | import org.springframework.stereotype.Service; |
| 20 | +import org.springframework.transaction.annotation.Transactional; | |
| 21 | 21 | |
| 22 | 22 | import javax.annotation.Resource; |
| 23 | 23 | import javax.validation.Valid; |
| 24 | - | |
| 25 | 24 | import java.util.List; |
| 26 | 25 | import java.util.Objects; |
| 27 | 26 | |
| 28 | 27 | import static cn.iocoder.yudao.adminserver.modules.system.enums.SysErrorCodeConstants.SOCIAL_AUTH_FAILURE; |
| 28 | +import static cn.iocoder.yudao.adminserver.modules.system.enums.SysErrorCodeConstants.SOCIAL_UNBIND_NOT_SELF; | |
| 29 | 29 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 30 | +import static cn.iocoder.yudao.framework.common.util.json.JsonUtils.toJsonString; | |
| 30 | 31 | |
| 31 | 32 | /** |
| 32 | 33 | * 社交 Service 实现类 |
| ... | ... | @@ -67,7 +68,7 @@ public class SysSocialServiceImpl implements SysSocialService { |
| 67 | 68 | |
| 68 | 69 | // 请求获取 |
| 69 | 70 | authUser = this.getAuthUser0(type, authCallback); |
| 70 | - // 缓存。原因是 code 有且可以使用一次。在社交登录时,当未绑定 User 时,需要绑定登陆,此时需要 code 使用两次 | |
| 71 | + // 缓存。原因是 code 有且可以使用一次。在社交登录时,当未绑定 User 时,需要绑定登录,此时需要 code 使用两次 | |
| 71 | 72 | authSocialUserRedisDAO.set(type, authCallback, authUser); |
| 72 | 73 | return authUser; |
| 73 | 74 | } |
| ... | ... | @@ -79,18 +80,19 @@ public class SysSocialServiceImpl implements SysSocialService { |
| 79 | 80 | } |
| 80 | 81 | |
| 81 | 82 | @Override |
| 83 | + public List<SysSocialUserDO> getSocialUserList(Long userId) { | |
| 84 | + return socialUserMapper.selectListByUserId(UserTypeEnum.ADMIN.getValue(), userId); | |
| 85 | + } | |
| 86 | + | |
| 87 | + @Override | |
| 88 | + @Transactional | |
| 82 | 89 | public void bindSocialUser(Long userId, Integer type, AuthUser authUser) { |
| 83 | 90 | // 获得 unionId 对应的 SysSocialUserDO 列表 |
| 84 | 91 | String unionId = getAuthUserUnionId(authUser); |
| 85 | 92 | List<SysSocialUserDO> socialUsers = this.getAllSocialUserList(type, unionId); |
| 86 | 93 | |
| 87 | 94 | // 逻辑一:如果 userId 之前绑定过该 type 的其它账号,需要进行解绑 |
| 88 | - List<Integer> types = SysSocialTypeEnum.getRelationTypes(type); | |
| 89 | - List<SysSocialUserDO> oldSocialUsers = socialUserMapper.selectListByTypeAndUserId(UserTypeEnum.ADMIN.getValue(), | |
| 90 | - types, userId); | |
| 91 | - if (CollUtil.isNotEmpty(oldSocialUsers) && !Objects.equals(unionId, oldSocialUsers.get(0).getUnionId())) { | |
| 92 | - socialUserMapper.deleteBatchIds(CollectionUtils.convertSet(oldSocialUsers, SysSocialUserDO::getId)); | |
| 93 | - } | |
| 95 | + this.unbindOldSocialUser(userId, type, unionId); | |
| 94 | 96 | |
| 95 | 97 | // 逻辑二:如果 socialUsers 指定的 userId 改变,需要进行更新 |
| 96 | 98 | // 例如说,一个微信 unionId 对应了多个社交账号,结果其中有个关联了新的 userId,则其它也要跟着修改 |
| ... | ... | @@ -103,25 +105,52 @@ public class SysSocialServiceImpl implements SysSocialService { |
| 103 | 105 | }); |
| 104 | 106 | |
| 105 | 107 | // 逻辑三:如果 authUser 不存在于 socialUsers 中,则进行新增;否则,进行更新 |
| 106 | - SysSocialUserDO saveSocialUser = CollUtil.findOneByField(socialUsers, "openid", authUser.getUuid()); | |
| 107 | - if (saveSocialUser == null) { | |
| 108 | - saveSocialUser = new SysSocialUserDO(); | |
| 109 | - saveSocialUser.setUserId(userId).setUserType(UserTypeEnum.ADMIN.getValue()); | |
| 110 | - saveSocialUser.setType(type).setOpenid(authUser.getUuid()).setToken(authUser.getToken().getAccessToken()) | |
| 111 | - .setUnionId(unionId).setRawTokenInfo(JsonUtils.toJsonString(authUser.getToken())); | |
| 112 | - saveSocialUser.setNickname(authUser.getNickname()).setAvatar(authUser.getAvatar()) | |
| 113 | - .setRawUserInfo(JsonUtils.toJsonString(authUser.getRawUserInfo())); | |
| 108 | + SysSocialUserDO socialUser = CollUtil.findOneByField(socialUsers, "openid", authUser.getUuid()); | |
| 109 | + SysSocialUserDO saveSocialUser = SysSocialUserDO.builder() // 新增和更新的通用属性 | |
| 110 | + .token(authUser.getToken().getAccessToken()).rawUserInfo(toJsonString(authUser.getToken())) | |
| 111 | + .nickname(authUser.getNickname()).avatar(authUser.getAvatar()).rawUserInfo(toJsonString(authUser.getRawUserInfo())) | |
| 112 | + .build(); | |
| 113 | + if (socialUser == null) { | |
| 114 | + saveSocialUser.setUserId(userId).setUserType(UserTypeEnum.ADMIN.getValue()) | |
| 115 | + .setType(type).setOpenid(authUser.getUuid()).setUnionId(unionId); | |
| 114 | 116 | socialUserMapper.insert(saveSocialUser); |
| 115 | 117 | } else { |
| 116 | - saveSocialUser = new SysSocialUserDO().setId(saveSocialUser.getId()); | |
| 117 | - saveSocialUser.setToken(authUser.getToken().getAccessToken()) | |
| 118 | - .setRawTokenInfo(JsonUtils.toJsonString(authUser.getToken())); | |
| 119 | - saveSocialUser.setNickname(authUser.getNickname()).setAvatar(authUser.getAvatar()) | |
| 120 | - .setRawUserInfo(JsonUtils.toJsonString(authUser.getRawUserInfo())); | |
| 118 | + saveSocialUser.setId(socialUser.getId()); | |
| 121 | 119 | socialUserMapper.updateById(saveSocialUser); |
| 122 | 120 | } |
| 123 | 121 | } |
| 124 | 122 | |
| 123 | + @Override | |
| 124 | + public void unbindSocialUser(Long userId, Integer type, String unionId) { | |
| 125 | + // 获得 unionId 对应的所有 SysSocialUserDO 社交用户 | |
| 126 | + List<SysSocialUserDO> socialUsers = this.getAllSocialUserList(type, unionId); | |
| 127 | + if (CollUtil.isEmpty(socialUsers)) { | |
| 128 | + return; | |
| 129 | + } | |
| 130 | + // 校验,是否解绑的是非自己的 | |
| 131 | + socialUsers.forEach(socialUser -> { | |
| 132 | + if (Objects.equals(socialUser.getUserId(), userId)) { | |
| 133 | + throw exception(SOCIAL_UNBIND_NOT_SELF); | |
| 134 | + } | |
| 135 | + }); | |
| 136 | + | |
| 137 | + // 解绑 | |
| 138 | + socialUserMapper.deleteBatchIds(CollectionUtils.convertSet(socialUsers, SysSocialUserDO::getId)); | |
| 139 | + } | |
| 140 | + | |
| 141 | + private void unbindOldSocialUser(Long userId, Integer type, String newUnionId) { | |
| 142 | + List<Integer> types = SysSocialTypeEnum.getRelationTypes(type); | |
| 143 | + List<SysSocialUserDO> oldSocialUsers = socialUserMapper.selectListByTypeAndUserId(UserTypeEnum.ADMIN.getValue(), | |
| 144 | + types, userId); | |
| 145 | + // 如果新老的 unionId 是一致的,说明无需解绑 | |
| 146 | + if (CollUtil.isEmpty(oldSocialUsers) || Objects.equals(newUnionId, oldSocialUsers.get(0).getUnionId())) { | |
| 147 | + return; | |
| 148 | + } | |
| 149 | + | |
| 150 | + // 解绑 | |
| 151 | + socialUserMapper.deleteBatchIds(CollectionUtils.convertSet(oldSocialUsers, SysSocialUserDO::getId)); | |
| 152 | + } | |
| 153 | + | |
| 125 | 154 | /** |
| 126 | 155 | * 请求社交平台,获得授权的用户 |
| 127 | 156 | * |
| ... | ... | @@ -132,8 +161,8 @@ public class SysSocialServiceImpl implements SysSocialService { |
| 132 | 161 | private AuthUser getAuthUser0(Integer type, AuthCallback authCallback) { |
| 133 | 162 | AuthRequest authRequest = authRequestFactory.get(SysSocialTypeEnum.valueOfType(type).getSource()); |
| 134 | 163 | AuthResponse<?> authResponse = authRequest.login(authCallback); |
| 135 | - log.info("[getAuthUser0][请求社交平台 type({}) request({}) response({})]", type, JsonUtils.toJsonString(authCallback), | |
| 136 | - JsonUtils.toJsonString(authResponse)); | |
| 164 | + log.info("[getAuthUser0][请求社交平台 type({}) request({}) response({})]", type, toJsonString(authCallback), | |
| 165 | + toJsonString(authResponse)); | |
| 137 | 166 | if (!authResponse.ok()) { |
| 138 | 167 | throw exception(SOCIAL_AUTH_FAILURE, authResponse.getMsg()); |
| 139 | 168 | } | ... | ... |
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 |
| 41 | 41 | Integer userType = UserTypeEnum.ADMIN.getValue(); |
| 42 | 42 | String templateCode = "test_01"; |
| 43 | 43 | Map<String, Object> templateParams = MapUtil.<String, Object>builder() |
| 44 | - .put("operation", "登陆").put("code", "1234").build(); | |
| 44 | + .put("operation", "登录").put("code", "1234").build(); | |
| 45 | 45 | // 调用 |
| 46 | 46 | smsService.sendSingleSms(mobile, userId, userType, templateCode, templateParams); |
| 47 | 47 | ... | ... |
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 { |
| 236 | 236 | when(authentication.getPrincipal()).thenReturn(loginUser); |
| 237 | 237 | // mock 获得 User 拥有的角色编号数组 |
| 238 | 238 | when(permissionService.getUserRoleIds(userId, singleton(CommonStatusEnum.ENABLE.getStatus()))).thenReturn(userRoleIds); |
| 239 | - // mock 缓存登陆用户到 Redis | |
| 239 | + // mock 缓存登录用户到 Redis | |
| 240 | 240 | when(userSessionService.createUserSession(loginUser, userIp, userAgent)).thenReturn(sessionId); |
| 241 | 241 | // 调用, 并断言异常 |
| 242 | 242 | String login = authService.login(reqVO, userIp, userAgent); | ... | ... |
yudao-admin-ui/src/api/login.js
| ... | ... | @@ -39,15 +39,15 @@ export function getCodeImg() { |
| 39 | 39 | }) |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | -// 社交登陆的跳转 | |
| 43 | -export function socialLoginRedirect(type, redirectUri) { | |
| 42 | +// 社交授权的跳转 | |
| 43 | +export function socialAuthRedirect(type, redirectUri) { | |
| 44 | 44 | return request({ |
| 45 | - url: '/social-login-redirect?type=' + type + '&redirectUri=' + redirectUri, | |
| 45 | + url: '/social-auth-redirect?type=' + type + '&redirectUri=' + redirectUri, | |
| 46 | 46 | method: 'get' |
| 47 | 47 | }) |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | -// 社交登陆,使用 code 授权码 | |
| 50 | +// 社交登录,使用 code 授权码 | |
| 51 | 51 | export function socialLogin(type, code, state) { |
| 52 | 52 | return request({ |
| 53 | 53 | url: '/social-login', |
| ... | ... | @@ -60,7 +60,7 @@ export function socialLogin(type, code, state) { |
| 60 | 60 | }) |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | -// 社交登陆,使用 code 授权码 + + 账号密码 | |
| 63 | +// 社交登录,使用 code 授权码 + + 账号密码 | |
| 64 | 64 | export function socialLogin2(type, code, state, username, password) { |
| 65 | 65 | return request({ |
| 66 | 66 | url: '/social-login2', | ... | ... |
yudao-admin-ui/src/store/modules/user.js
| ... | ... | @@ -47,7 +47,7 @@ const user = { |
| 47 | 47 | }) |
| 48 | 48 | }, |
| 49 | 49 | |
| 50 | - // 社交登陆 | |
| 50 | + // 社交登录 | |
| 51 | 51 | SocialLogin({ commit }, userInfo) { |
| 52 | 52 | const code = userInfo.code |
| 53 | 53 | const state = userInfo.state |
| ... | ... | @@ -64,7 +64,7 @@ const user = { |
| 64 | 64 | }) |
| 65 | 65 | }, |
| 66 | 66 | |
| 67 | - // 社交登陆 | |
| 67 | + // 社交登录 | |
| 68 | 68 | SocialLogin2({ commit }, userInfo) { |
| 69 | 69 | const code = userInfo.code |
| 70 | 70 | const state = userInfo.state | ... | ... |
yudao-admin-ui/src/views/index_old.vue
| ... | ... | @@ -419,7 +419,7 @@ |
| 419 | 419 | <li>修复表格时间为空出现的异常</li> |
| 420 | 420 | <li>添加Jackson日期反序列化时区配置</li> |
| 421 | 421 | <li>调整根据用户权限加载菜单数据树形结构</li> |
| 422 | - <li>调整成功登陆不恢复按钮,防止多次点击</li> | |
| 422 | + <li>调整成功登录不恢复按钮,防止多次点击</li> | |
| 423 | 423 | <li>修改用户个人资料同步缓存信息</li> |
| 424 | 424 | <li>修复页面同时出现el-upload和Editor不显示处理</li> |
| 425 | 425 | <li>修复在角色管理页修改菜单权限偶尔未选中问题</li> | ... | ... |
yudao-admin-ui/src/views/login.vue
| ... | ... | @@ -45,7 +45,7 @@ |
| 45 | 45 | </template> |
| 46 | 46 | |
| 47 | 47 | <script> |
| 48 | -import { getCodeImg,socialLoginRedirect } from "@/api/login"; | |
| 48 | +import { getCodeImg,socialAuthRedirect } from "@/api/login"; | |
| 49 | 49 | import Cookies from "js-cookie"; |
| 50 | 50 | import { encrypt, decrypt } from '@/utils/jsencrypt' |
| 51 | 51 | import {InfApiErrorLogProcessStatusEnum, SysUserSocialTypeEnum} from "@/utils/constants"; |
| ... | ... | @@ -133,14 +133,14 @@ export default { |
| 133 | 133 | }, |
| 134 | 134 | doSocialLogin(socialTypeEnum) { |
| 135 | 135 | // console.log("开始Oauth登录...%o", socialTypeEnum.code); |
| 136 | - // 设置登陆中 | |
| 136 | + // 设置登录中 | |
| 137 | 137 | this.loading = true; |
| 138 | 138 | // 计算 redirectUri |
| 139 | 139 | const redirectUri = location.origin + '/social-login?type=' + socialTypeEnum.type + '&redirect=' + (this.redirect || "/"); // 重定向不能丢 |
| 140 | 140 | // const redirectUri = 'http://127.0.0.1:48080/api/gitee/callback'; |
| 141 | 141 | // const redirectUri = 'http://127.0.0.1:48080/api/dingtalk/callback'; |
| 142 | 142 | // 进行跳转 |
| 143 | - socialLoginRedirect(socialTypeEnum.type, encodeURIComponent(redirectUri)).then((res) => { | |
| 143 | + socialAuthRedirect(socialTypeEnum.type, encodeURIComponent(redirectUri)).then((res) => { | |
| 144 | 144 | // console.log(res.url); |
| 145 | 145 | window.location.href = res.data; |
| 146 | 146 | }); | ... | ... |
yudao-admin-ui/src/views/socialLogin.vue
| ... | ... | @@ -51,7 +51,7 @@ export default { |
| 51 | 51 | }, |
| 52 | 52 | loading: false, |
| 53 | 53 | redirect: undefined, |
| 54 | - // 社交登陆相关 | |
| 54 | + // 社交登录相关 | |
| 55 | 55 | type: undefined, |
| 56 | 56 | code: undefined, |
| 57 | 57 | state: undefined, |
| ... | ... | @@ -70,7 +70,7 @@ export default { |
| 70 | 70 | // 重定向地址 |
| 71 | 71 | this.redirect = this.$route.query.redirect; |
| 72 | 72 | debugger |
| 73 | - // 社交登陆相关 | |
| 73 | + // 社交登录相关 | |
| 74 | 74 | this.type = this.$route.query.type; |
| 75 | 75 | this.code = this.$route.query.code; |
| 76 | 76 | this.state = this.$route.query.state; | ... | ... |
yudao-admin-ui/src/views/system/loginlog/index.vue
yudao-admin-ui/src/views/system/session/index.vue
| ... | ... | @@ -17,7 +17,7 @@ |
| 17 | 17 | <el-table-column label="会话编号" align="center" prop="id" width="300" /> |
| 18 | 18 | <el-table-column label="登录名称" align="center" prop="username" width="100" /> |
| 19 | 19 | <el-table-column label="部门名称" align="center" prop="deptName" width="100" /> |
| 20 | - <el-table-column label="登陆地址" align="center" prop="userIp" width="100" /> | |
| 20 | + <el-table-column label="登录地址" align="center" prop="userIp" width="100" /> | |
| 21 | 21 | <el-table-column label="userAgent" align="center" prop="userAgent" :show-overflow-tooltip="true" /> |
| 22 | 22 | <el-table-column label="登录时间" align="center" prop="createTime" width="180"> |
| 23 | 23 | <template slot-scope="scope"> | ... | ... |
yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/security/config/YudaoSecurityAutoConfiguration.java
yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/security/config/YudaoWebSecurityConfigurerAdapter.java
| ... | ... | @@ -131,7 +131,7 @@ public class YudaoWebSecurityConfigurerAdapter extends WebSecurityConfigurerAdap |
| 131 | 131 | |
| 132 | 132 | // 设置每个请求的权限 ①:全局共享规则 |
| 133 | 133 | httpSecurity.authorizeRequests() |
| 134 | - // 登陆的接口,可匿名访问 | |
| 134 | + // 登录的接口,可匿名访问 | |
| 135 | 135 | .antMatchers(api("/login")).anonymous() |
| 136 | 136 | // 静态资源,可匿名访问 |
| 137 | 137 | .antMatchers(HttpMethod.GET, "/*.html", "/**/*.html", "/**/*.css", "/**/*.js").permitAll() | ... | ... |
yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/security/core/LoginUser.java
yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/security/core/annotations/PreAuthenticated.java
| ... | ... | @@ -3,9 +3,9 @@ package cn.iocoder.yudao.framework.security.core.annotations; |
| 3 | 3 | import java.lang.annotation.*; |
| 4 | 4 | |
| 5 | 5 | /** |
| 6 | - * 声明用户需要登陆 | |
| 6 | + * 声明用户需要登录 | |
| 7 | 7 | * |
| 8 | - * 为什么不使用 {@link org.springframework.security.access.prepost.PreAuthorize} 注解,原因是不通过时,抛出的是认证不通过,而不是未登陆 | |
| 8 | + * 为什么不使用 {@link org.springframework.security.access.prepost.PreAuthorize} 注解,原因是不通过时,抛出的是认证不通过,而不是未登录 | |
| 9 | 9 | * |
| 10 | 10 | * @author 芋道源码 |
| 11 | 11 | */ | ... | ... |
yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/security/core/filter/JwtAuthenticationTokenFilter.java
yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/security/core/util/SecurityFrameworkUtils.java
yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/core/filter/DemoFilter.java
| ... | ... | @@ -23,7 +23,7 @@ public class DemoFilter extends OncePerRequestFilter { |
| 23 | 23 | protected boolean shouldNotFilter(HttpServletRequest request) { |
| 24 | 24 | String method = request.getMethod(); |
| 25 | 25 | return !StrUtil.equalsAnyIgnoreCase(method, "POST", "PUT", "DELETE") // 写操作时,不进行过滤率 |
| 26 | - || WebFrameworkUtils.getLoginUserId(request) == null; // 非登陆用户时,不进行过滤 | |
| 26 | + || WebFrameworkUtils.getLoginUserId(request) == null; // 非登录用户时,不进行过滤 | |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | @Override | ... | ... |
yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/infra/service/auth/SysAuthService.java