优化管理后台的社交登录

This commit is contained in:
YunaiV
2022-07-05 22:00:23 +08:00
parent 2b9b302368
commit 8751471aa1
11 changed files with 75 additions and 137 deletions

View File

@ -3,12 +3,15 @@ import {getRefreshToken} from "@/utils/auth";
import service from "@/utils/request";
// 登录方法
export function login(username, password, code, uuid) {
export function login(username, password, code, uuid,
socialType, socialCode, socialState) {
const data = {
username,
password,
code,
uuid
uuid,
// 社交相关
socialType, socialCode, socialState
}
return request({
url: '/system/auth/login',
@ -51,9 +54,9 @@ export function socialAuthRedirect(type, redirectUri) {
}
// 社交快捷登录,使用 code 授权码
export function socialQuickLogin(type, code, state) {
export function socialLogin(type, code, state) {
return request({
url: '/system/auth/social-quick-login',
url: '/system/auth/social-login',
method: 'post',
data: {
type,
@ -63,21 +66,6 @@ export function socialQuickLogin(type, code, state) {
})
}
// 社交绑定登录,使用 code 授权码 + + 账号密码
export function socialBindLogin(type, code, state, username, password) {
return request({
url: '/system/auth/social-bind-login',
method: 'post',
data: {
type,
code,
state,
username,
password
}
})
}
// 获取登录验证码
export function sendSmsCode(mobile, scene) {
return request({

View File

@ -1,4 +1,4 @@
import {login, logout, getInfo, socialQuickLogin, socialBindLogin, smsLogin} from '@/api/login'
import {login, logout, getInfo, socialLogin, socialBindLogin, smsLogin} from '@/api/login'
import {getAccessToken, setToken, removeToken, getRefreshToken} from '@/utils/auth'
const user = {
@ -38,8 +38,12 @@ const user = {
const password = userInfo.password
const code = userInfo.code
const uuid = userInfo.uuid
const socialCode = userInfo.socialCode
const socialState = userInfo.socialState
const socialType = userInfo.socialType
return new Promise((resolve, reject) => {
login(username, password, code, uuid).then(res => {
login(username, password, code, uuid,
socialType, socialCode, socialState).then(res => {
res = res.data;
// 设置 token
setToken(res)
@ -56,7 +60,7 @@ const user = {
const state = userInfo.state
const type = userInfo.type
return new Promise((resolve, reject) => {
socialQuickLogin(type, code, state).then(res => {
socialLogin(type, code, state).then(res => {
res = res.data;
// 设置 token
setToken(res)
@ -67,25 +71,7 @@ const user = {
})
},
// 社交登录
SocialLogin2({ commit }, userInfo) {
const code = userInfo.code
const state = userInfo.state
const type = userInfo.type
const username = userInfo.username.trim()
const password = userInfo.password
return new Promise((resolve, reject) => {
socialBindLogin(type, code, state, username, password).then(res => {
res = res.data;
// 设置 token
setToken(res)
resolve()
}).catch(error => {
reject(error)
})
})
},
// 登录
// 短信登录
SmsLogin({ commit }, userInfo) {
const mobile = userInfo.mobile.trim()
const mobileCode = userInfo.mobileCode

View File

@ -87,6 +87,8 @@ export default {
username: "admin",
password: "admin123",
rememberMe: false,
code: "",
uuid: "",
},
loginRules: {
username: [
@ -170,16 +172,20 @@ export default {
removeUsername()
removePassword()
}
this.$store.dispatch("SocialLogin2", {
code: this.code,
state: this.state,
type: this.type,
this.$store.dispatch("Login", {
socialCode: this.code,
socialState: this.state,
socialType: this.type,
// 账号密码登录
username: this.loginForm.username,
password: this.loginForm.password
password: this.loginForm.password,
code: this.loginForm.code,
uuid: this.loginForm.uuid,
}).then(() => {
this.$router.push({ path: this.redirect || "/" }).catch(()=>{});
}).catch(() => {
this.loading = false;
this.getCode()
});
}
});