Skip to content

Commit 2b366d9

Browse files
committed
进一步重构社交登陆的实现
1 parent f03ec30 commit 2b366d9

File tree

7 files changed

+45
-50
lines changed

7 files changed

+45
-50
lines changed

src/api/login.js

Lines changed: 9 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export function login(username, password, code, uuid) {
99
uuid
1010
}
1111
return request({
12-
url: '/system/login',
12+
url: '/system/auth/login',
1313
method: 'post',
1414
data: data
1515
})
@@ -18,7 +18,7 @@ export function login(username, password, code, uuid) {
1818
// 获取用户详细信息
1919
export function getInfo() {
2020
return request({
21-
url: '/system/get-permission-info',
21+
url: '/system/auth/get-permission-info',
2222
method: 'get'
2323
})
2424
}
@@ -43,15 +43,15 @@ export function getCodeImg() {
4343
// 社交授权的跳转
4444
export function socialAuthRedirect(type, redirectUri) {
4545
return request({
46-
url: '/system/social-auth-redirect?type=' + type + '&redirectUri=' + redirectUri,
46+
url: '/system/auth/social-auth-redirect?type=' + type + '&redirectUri=' + redirectUri,
4747
method: 'get'
4848
})
4949
}
5050

51-
// 社交登录,使用 code 授权码
52-
export function socialLogin(type, code, state) {
51+
// 社交快捷登录,使用 code 授权码
52+
export function socialQuickLogin(type, code, state) {
5353
return request({
54-
url: '/system/social-login',
54+
url: '/system/auth/social-quick-login',
5555
method: 'post',
5656
data: {
5757
type,
@@ -61,10 +61,10 @@ export function socialLogin(type, code, state) {
6161
})
6262
}
6363

64-
// 社交登录,使用 code 授权码 + + 账号密码
65-
export function socialLogin2(type, code, state, username, password) {
64+
// 社交绑定登录,使用 code 授权码 + + 账号密码
65+
export function socialBindLogin(type, code, state, username, password) {
6666
return request({
67-
url: '/system/social-login2',
67+
url: '/system/auth/social-bind-login',
6868
method: 'post',
6969
data: {
7070
type,
@@ -75,28 +75,3 @@ export function socialLogin2(type, code, state, username, password) {
7575
}
7676
})
7777
}
78-
79-
// 社交绑定,使用 code 授权码
80-
export function socialBind(type, code, state) {
81-
return request({
82-
url: '/system/social-bind',
83-
method: 'post',
84-
data: {
85-
type,
86-
code,
87-
state,
88-
}
89-
})
90-
}
91-
92-
// 取消社交绑定
93-
export function socialUnbind(type, unionId) {
94-
return request({
95-
url: '/system/social-unbind',
96-
method: 'delete',
97-
data: {
98-
type,
99-
unionId
100-
}
101-
})
102-
}

src/api/menu.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import request from '@/utils/request'
33
// 获取路由
44
export const getRouters = () => {
55
return request({
6-
url: '/system/list-menus',
6+
url: '/system/auth/list-menus',
77
method: 'get'
88
})
99
}

src/api/system/socialUser.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import request from "@/utils/request";
2+
3+
// 社交绑定,使用 code 授权码
4+
export function socialBind(type, code, state) {
5+
return request({
6+
url: '/system/social-user/bind',
7+
method: 'post',
8+
data: {
9+
type,
10+
code,
11+
state,
12+
}
13+
})
14+
}
15+
16+
// 取消社交绑定
17+
export function socialUnbind(type, unionId) {
18+
return request({
19+
url: '/system/social-user/unbind',
20+
method: 'delete',
21+
data: {
22+
type,
23+
unionId
24+
}
25+
})
26+
}

src/store/modules/user.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {login, logout, getInfo, socialLogin, socialLogin2} from '@/api/login'
1+
import {login, logout, getInfo, socialQuickLogin, socialBindLogin} from '@/api/login'
22
import { getToken, setToken, removeToken } from '@/utils/auth'
33

44
const user = {
@@ -57,7 +57,7 @@ const user = {
5757
const state = userInfo.state
5858
const type = userInfo.type
5959
return new Promise((resolve, reject) => {
60-
socialLogin(type, code, state).then(res => {
60+
socialQuickLogin(type, code, state).then(res => {
6161
res = res.data;
6262
setToken(res.token)
6363
commit('SET_TOKEN', res.token)
@@ -76,7 +76,7 @@ const user = {
7676
const username = userInfo.username.trim()
7777
const password = userInfo.password
7878
return new Promise((resolve, reject) => {
79-
socialLogin2(type, code, state, username, password).then(res => {
79+
socialBindLogin(type, code, state, username, password).then(res => {
8080
res = res.data;
8181
setToken(res.token)
8282
commit('SET_TOKEN', res.token)

src/utils/constants.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,6 @@ export const InfraApiErrorLogProcessStatusEnum = {
7171
* 用户的社交平台的类型枚举
7272
*/
7373
export const SystemUserSocialTypeEnum = {
74-
// GITEE: {
75-
// title: "码云",
76-
// type: 10,
77-
// source: "gitee",
78-
// img: "https://cdn.jsdelivr.net/gh/justauth/[email protected]/gitee.png",
79-
// },
8074
DINGTALK: {
8175
title: "钉钉",
8276
type: 20,

src/views/login.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,6 @@ export default {
176176
});
177177
},
178178
doSocialLogin(socialTypeEnum) {
179-
// console.log("开始Oauth登录...%o", socialTypeEnum.code);
180179
// 设置登录中
181180
this.loading = true;
182181
// 计算 redirectUri

src/views/system/user/profile/userSocial.vue

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
</el-table-column>
88
<el-table-column label="操作" align="left" >
99
<template slot-scope="scope">
10-
<div v-if="scope.row.unionId">
10+
<div v-if="scope.row.openid">
1111
已绑定
1212
<el-button size="large" type="text" @click="unbind(scope.row)">(解绑)</el-button>
1313
</div>
@@ -23,7 +23,8 @@
2323
<script>
2424
2525
import {SystemUserSocialTypeEnum} from "@/utils/constants";
26-
import {socialAuthRedirect, socialBind, socialUnbind} from "@/api/login";
26+
import {socialAuthRedirect} from "@/api/login";
27+
import {socialBind, socialUnbind} from "@/api/system/socialUser";
2728
2829
export default {
2930
props: {
@@ -50,7 +51,7 @@ export default {
5051
if (this.user.socialUsers) {
5152
for (const j in this.user.socialUsers) {
5253
if (socialUser.type === this.user.socialUsers[j].type) {
53-
socialUser.unionId = this.user.socialUsers[j].unionId;
54+
socialUser.openid = this.user.socialUsers[j].openid;
5455
break;
5556
}
5657
}
@@ -86,9 +87,9 @@ export default {
8687
});
8788
},
8889
unbind(socialUser) {
89-
socialUnbind(socialUser.type, socialUser.unionId).then(resp => {
90+
socialUnbind(socialUser.type, socialUser.openid).then(resp => {
9091
this.$modal.msgSuccess("解绑成功");
91-
socialUser.unionId = undefined;
92+
socialUser.openid = undefined;
9293
});
9394
},
9495
close() {

0 commit comments

Comments
 (0)