Commit a0a5d3a35741cdbbc39e9448b95d912cc87b4185
1 parent
7b3a2830
1. 优化前端的社交登陆的枚举
2. 将三方登陆,统一改成社交登陆
Showing
9 changed files
with
63 additions
and
75 deletions
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/auth/SysAuthController.java
| ... | ... | @@ -105,7 +105,7 @@ public class SysAuthController { |
| 105 | 105 | @GetMapping("/social-login-redirect") |
| 106 | 106 | @ApiOperation("社交登陆的跳转") |
| 107 | 107 | @ApiImplicitParams({ |
| 108 | - @ApiImplicitParam(name = "type", value = "三方类型", required = true, dataTypeClass = Integer.class), | |
| 108 | + @ApiImplicitParam(name = "type", value = "社交类型", required = true, dataTypeClass = Integer.class), | |
| 109 | 109 | @ApiImplicitParam(name = "redirectUri", value = "回调路径", dataTypeClass = String.class) |
| 110 | 110 | }) |
| 111 | 111 | public CommonResult<String> socialLoginRedirect(@RequestParam("type") Integer type, | ... | ... |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/redis/SysRedisKeyConstants.java
| ... | ... | @@ -23,7 +23,7 @@ public interface SysRedisKeyConstants { |
| 23 | 23 | "captcha_code:%s", // 参数为 uuid |
| 24 | 24 | STRING, String.class, RedisKeyDefine.TimeoutTypeEnum.DYNAMIC); |
| 25 | 25 | |
| 26 | - RedisKeyDefine AUTH_SOCIAL_USER = new RedisKeyDefine("认证的三方用户", | |
| 26 | + RedisKeyDefine AUTH_SOCIAL_USER = new RedisKeyDefine("认证的社交用户", | |
| 27 | 27 | "auth_social_user:%d:%s", // 参数为 type,code |
| 28 | 28 | STRING, AuthUser.class, Duration.ofDays(1)); |
| 29 | 29 | ... | ... |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/enums/SysErrorCodeConstants.java
| ... | ... | @@ -17,7 +17,7 @@ public interface SysErrorCodeConstants { |
| 17 | 17 | ErrorCode AUTH_LOGIN_CAPTCHA_NOT_FOUND = new ErrorCode(1002000003, "验证码不存在"); |
| 18 | 18 | ErrorCode AUTH_LOGIN_CAPTCHA_CODE_ERROR = new ErrorCode(1002000004, "验证码不正确"); |
| 19 | 19 | ErrorCode AUTH_THIRD_LOGIN_NOT_BIND = new ErrorCode(1002000005, "未绑定账号,需要进行绑定"); |
| 20 | - ErrorCode AUTH_THIRD_OAUTH_FAILURE = new ErrorCode(1002000006, "三方授权失败,原因是:{}"); | |
| 20 | + ErrorCode AUTH_THIRD_OAUTH_FAILURE = new ErrorCode(1002000006, "社交授权失败,原因是:{}"); | |
| 21 | 21 | |
| 22 | 22 | // ========== TOKEN 模块 1002001000 ========== |
| 23 | 23 | ErrorCode TOKEN_EXPIRED = new ErrorCode(1002001000, "Token 已经过期"); | ... | ... |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/auth/impl/SysAuthServiceImpl.java
| ... | ... | @@ -258,7 +258,7 @@ public class SysAuthServiceImpl implements SysAuthService { |
| 258 | 258 | private AuthUser obtainAuthUser(Integer type, AuthCallback authCallback) { |
| 259 | 259 | AuthRequest authRequest = authRequestFactory.get(SysSocialTypeEnum.valueOfType(type).getSource()); |
| 260 | 260 | AuthResponse<?> authResponse = authRequest.login(authCallback); |
| 261 | - log.info("[obtainAuthUser][请求三方平台 type({}) request({}) response({})]", type, JsonUtils.toJsonString(authCallback), | |
| 261 | + log.info("[obtainAuthUser][请求社交平台 type({}) request({}) response({})]", type, JsonUtils.toJsonString(authCallback), | |
| 262 | 262 | JsonUtils.toJsonString(authResponse)); |
| 263 | 263 | if (!authResponse.ok()) { |
| 264 | 264 | throw exception(AUTH_THIRD_OAUTH_FAILURE, authResponse.getMsg()); | ... | ... |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/user/SysUserService.java
| ... | ... | @@ -35,14 +35,6 @@ public interface SysUserService { |
| 35 | 35 | Long createUser(SysUserCreateReqVO reqVO); |
| 36 | 36 | |
| 37 | 37 | /** |
| 38 | - * 绑定第三方用户 | |
| 39 | - * @param sysUserId 系统用户ID | |
| 40 | - * @param socialUSerId 第三方唯一标识 | |
| 41 | - * @return | |
| 42 | - */ | |
| 43 | - Long bindSocialUSer(Long sysUserId, String socialUSerId); | |
| 44 | - | |
| 45 | - /** | |
| 46 | 38 | * 修改用户 |
| 47 | 39 | * |
| 48 | 40 | * @param reqVO 用户信息 | ... | ... |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/user/SysUserServiceImpl.java
| ... | ... | @@ -4,11 +4,6 @@ import cn.hutool.core.collection.CollUtil; |
| 4 | 4 | import cn.hutool.core.io.IoUtil; |
| 5 | 5 | import cn.hutool.core.util.IdUtil; |
| 6 | 6 | import cn.hutool.core.util.StrUtil; |
| 7 | -import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.user.SysSocialUserDO; | |
| 8 | -import cn.iocoder.yudao.adminserver.modules.system.dal.mysql.social.SysUserSocialMapper; | |
| 9 | -import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | |
| 10 | -import cn.iocoder.yudao.framework.common.exception.ServiceException; | |
| 11 | -import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 12 | 7 | import cn.iocoder.yudao.adminserver.modules.infra.service.file.InfFileService; |
| 13 | 8 | import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.profile.SysUserProfileUpdatePasswordReqVO; |
| 14 | 9 | import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.profile.SysUserProfileUpdateReqVO; |
| ... | ... | @@ -17,10 +12,14 @@ import cn.iocoder.yudao.adminserver.modules.system.convert.user.SysUserConvert; |
| 17 | 12 | import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.dept.SysDeptDO; |
| 18 | 13 | import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.dept.SysPostDO; |
| 19 | 14 | import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.user.SysUserDO; |
| 15 | +import cn.iocoder.yudao.adminserver.modules.system.dal.mysql.social.SysUserSocialMapper; | |
| 20 | 16 | import cn.iocoder.yudao.adminserver.modules.system.dal.mysql.user.SysUserMapper; |
| 21 | 17 | import cn.iocoder.yudao.adminserver.modules.system.service.dept.SysDeptService; |
| 22 | 18 | import cn.iocoder.yudao.adminserver.modules.system.service.dept.SysPostService; |
| 23 | 19 | import cn.iocoder.yudao.adminserver.modules.system.service.permission.SysPermissionService; |
| 20 | +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | |
| 21 | +import cn.iocoder.yudao.framework.common.exception.ServiceException; | |
| 22 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 24 | 23 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; |
| 25 | 24 | import com.google.common.annotations.VisibleForTesting; |
| 26 | 25 | import lombok.extern.slf4j.Slf4j; |
| ... | ... | @@ -33,9 +32,8 @@ import javax.annotation.Resource; |
| 33 | 32 | import java.io.InputStream; |
| 34 | 33 | import java.util.*; |
| 35 | 34 | |
| 36 | -import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | |
| 37 | 35 | import static cn.iocoder.yudao.adminserver.modules.system.enums.SysErrorCodeConstants.*; |
| 38 | - | |
| 36 | +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | |
| 39 | 37 | |
| 40 | 38 | /** |
| 41 | 39 | * 用户 Service 实现类 |
| ... | ... | @@ -79,15 +77,6 @@ public class SysUserServiceImpl implements SysUserService { |
| 79 | 77 | } |
| 80 | 78 | |
| 81 | 79 | @Override |
| 82 | - public Long bindSocialUSer(Long sysUserId, String socialUSerId) { | |
| 83 | - SysSocialUserDO userSocialDO = new SysSocialUserDO(); | |
| 84 | - userSocialDO.setUserId(sysUserId); | |
| 85 | -// userSocialDO.setSocialUserId(socialUSerId); | |
| 86 | - userSocialMapper.insert(userSocialDO); | |
| 87 | - return userSocialDO.getUserId(); | |
| 88 | - } | |
| 89 | - | |
| 90 | - @Override | |
| 91 | 80 | public void updateUser(SysUserUpdateReqVO reqVO) { |
| 92 | 81 | // 校验正确性 |
| 93 | 82 | this.checkCreateOrUpdate(reqVO.getId(), reqVO.getUsername(), reqVO.getMobile(), reqVO.getEmail(), | ... | ... |
yudao-admin-ui/src/utils/constants.js
| ... | ... | @@ -68,9 +68,25 @@ export const InfApiErrorLogProcessStatusEnum = { |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | /** |
| 71 | - * 用户的三方平台的类型枚举 | |
| 71 | + * 用户的社交平台的类型枚举 | |
| 72 | 72 | */ |
| 73 | 73 | export const SysUserSocialTypeEnum = { |
| 74 | - GITEE: 10, | |
| 75 | - DINGTALK: 20, | |
| 74 | + // GITEE: { | |
| 75 | + // title: "码云", | |
| 76 | + // type: 10, | |
| 77 | + // source: "gitee", | |
| 78 | + // img: "https://cdn.jsdelivr.net/gh/justauth/justauth-oauth-logo@1.11/gitee.png", | |
| 79 | + // }, | |
| 80 | + DINGTALK: { | |
| 81 | + title: "钉钉", | |
| 82 | + type: 20, | |
| 83 | + source: "dingtalk", | |
| 84 | + img: "https://cdn.jsdelivr.net/gh/justauth/justauth-oauth-logo@1.11/dingtalk.png", | |
| 85 | + }, | |
| 86 | + WECHAT_ENTERPRISE: { | |
| 87 | + title: "企业微信", | |
| 88 | + type: 30, | |
| 89 | + source: "wechat_enterprise", | |
| 90 | + img: "https://cdn.jsdelivr.net/gh/justauth/justauth-oauth-logo@1.11/wechat_enterprise.png", | |
| 91 | + } | |
| 76 | 92 | } | ... | ... |
yudao-admin-ui/src/views/login.vue
| ... | ... | @@ -30,8 +30,8 @@ |
| 30 | 30 | |
| 31 | 31 | <el-form-item style="width:100%;"> |
| 32 | 32 | <div class="oauth-login" style="display:flex"> |
| 33 | - <div class="oauth-login-item" v-for="item in oauthProviders" :key="item.code" @click="doAuth2Login(item)"> | |
| 34 | - <img :src=item.img height="25px" width="25px" alt="登录" > | |
| 33 | + <div class="oauth-login-item" v-for="item in SysUserSocialTypeEnum" :key="item.type" @click="doSocialLogin(item)"> | |
| 34 | + <img :src="item.img" height="25px" width="25px" alt="登录" > | |
| 35 | 35 | <span>{{item.title}}</span> |
| 36 | 36 | </div> |
| 37 | 37 | </div> |
| ... | ... | @@ -48,6 +48,7 @@ |
| 48 | 48 | import { getCodeImg,socialLoginRedirect } from "@/api/login"; |
| 49 | 49 | import Cookies from "js-cookie"; |
| 50 | 50 | import { encrypt, decrypt } from '@/utils/jsencrypt' |
| 51 | +import {InfApiErrorLogProcessStatusEnum, SysUserSocialTypeEnum} from "@/utils/constants"; | |
| 51 | 52 | |
| 52 | 53 | export default { |
| 53 | 54 | name: "Login", |
| ... | ... | @@ -61,23 +62,6 @@ export default { |
| 61 | 62 | code: "", |
| 62 | 63 | uuid: "" |
| 63 | 64 | }, |
| 64 | - oauthProviders: [{ | |
| 65 | - img: "https://cdn.jsdelivr.net/gh/justauth/justauth-oauth-logo@1.2/gitee.png", | |
| 66 | - title: "码云", | |
| 67 | - source: "gitee", | |
| 68 | - type: 10 | |
| 69 | - }, { | |
| 70 | - img: "https://cdn.jsdelivr.net/gh/justauth/justauth-oauth-logo@1.2/dingtalk.png", | |
| 71 | - title: "钉钉", | |
| 72 | - source: "dingtalk", | |
| 73 | - type: 20 | |
| 74 | - } , { | |
| 75 | - img: "https://cdn.jsdelivr.net/gh/justauth/justauth-oauth-logo@1.2/wechat_enterprise.png", | |
| 76 | - title: "企业微信", | |
| 77 | - source: "wechat_enterprise", | |
| 78 | - type: 30 | |
| 79 | - } | |
| 80 | - ], | |
| 81 | 65 | loginRules: { |
| 82 | 66 | username: [ |
| 83 | 67 | { required: true, trigger: "blur", message: "用户名不能为空" } |
| ... | ... | @@ -88,18 +72,22 @@ export default { |
| 88 | 72 | code: [{ required: true, trigger: "change", message: "验证码不能为空" }] |
| 89 | 73 | }, |
| 90 | 74 | loading: false, |
| 91 | - redirect: undefined | |
| 75 | + redirect: undefined, | |
| 76 | + // 枚举 | |
| 77 | + SysUserSocialTypeEnum: SysUserSocialTypeEnum, | |
| 92 | 78 | }; |
| 93 | 79 | }, |
| 94 | - watch: { | |
| 95 | - $route: { | |
| 96 | - handler: function(route) { | |
| 97 | - this.redirect = route.query && route.query.redirect; | |
| 98 | - }, | |
| 99 | - immediate: true | |
| 100 | - } | |
| 101 | - }, | |
| 80 | + // watch: { | |
| 81 | + // $route: { | |
| 82 | + // handler: function(route) { | |
| 83 | + // this.redirect = route.query && route.query.redirect; | |
| 84 | + // }, | |
| 85 | + // immediate: true | |
| 86 | + // } | |
| 87 | + // }, | |
| 102 | 88 | created() { |
| 89 | + // 重定向地址 | |
| 90 | + this.redirect = this.$route.query.redirect; | |
| 103 | 91 | this.getCode(); |
| 104 | 92 | this.getCookie(); |
| 105 | 93 | }, |
| ... | ... | @@ -143,16 +131,16 @@ export default { |
| 143 | 131 | } |
| 144 | 132 | }); |
| 145 | 133 | }, |
| 146 | - doAuth2Login(provider) { | |
| 147 | - // console.log("开始Oauth登录...%o", provider.code); | |
| 134 | + doSocialLogin(socialTypeEnum) { | |
| 135 | + // console.log("开始Oauth登录...%o", socialTypeEnum.code); | |
| 148 | 136 | // 设置登陆中 |
| 149 | 137 | this.loading = true; |
| 150 | 138 | // 计算 redirectUri |
| 151 | - // const redirectUri = location.origin + '/social-login'; | |
| 152 | - const redirectUri = 'http://127.0.0.1:48080/api/gitee/callback'; | |
| 139 | + const redirectUri = location.origin + '/social-login?type=' + socialTypeEnum.type + '&redirect=' + (this.redirect || "/"); // 重定向不能丢 | |
| 140 | + // const redirectUri = 'http://127.0.0.1:48080/api/gitee/callback'; | |
| 153 | 141 | // const redirectUri = 'http://127.0.0.1:48080/api/dingtalk/callback'; |
| 154 | 142 | // 进行跳转 |
| 155 | - socialLoginRedirect(provider.type, redirectUri).then((res) => { | |
| 143 | + socialLoginRedirect(socialTypeEnum.type, encodeURIComponent(redirectUri)).then((res) => { | |
| 156 | 144 | // console.log(res.url); |
| 157 | 145 | window.location.href = res.data; |
| 158 | 146 | }); | ... | ... |
yudao-admin-ui/src/views/socialLogin.vue
| ... | ... | @@ -51,24 +51,27 @@ 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, |
| 58 | 58 | }; |
| 59 | 59 | }, |
| 60 | - watch: { | |
| 61 | - $route: { | |
| 62 | - handler: function(route) { | |
| 63 | - this.redirect = route.query && route.query.redirect; | |
| 64 | - }, | |
| 65 | - immediate: true | |
| 66 | - } | |
| 67 | - }, | |
| 60 | + // watch: { | |
| 61 | + // $route: { | |
| 62 | + // handler: function(route) { | |
| 63 | + // this.redirect = route.query && route.query.redirect; | |
| 64 | + // }, | |
| 65 | + // immediate: true | |
| 66 | + // } | |
| 67 | + // }, | |
| 68 | 68 | created() { |
| 69 | 69 | this.getCookie(); |
| 70 | - // 三方登陆相关 | |
| 71 | - this.type = 10; // TODO 芋艿:需要改 | |
| 70 | + // 重定向地址 | |
| 71 | + this.redirect = this.$route.query.redirect; | |
| 72 | + debugger | |
| 73 | + // 社交登陆相关 | |
| 74 | + this.type = this.$route.query.type; | |
| 72 | 75 | this.code = this.$route.query.code; |
| 73 | 76 | this.state = this.$route.query.state; |
| 74 | 77 | this.$store.dispatch("SocialLogin", { | ... | ... |