✨ obtain user login device information
This commit is contained in:
17
src/api/oauth/index.ts
Normal file
17
src/api/oauth/index.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import {service} from "@/utils/alova/service.ts";
|
||||
|
||||
/**
|
||||
* 获取用户设备信息
|
||||
*/
|
||||
export const getUserDevice = (userId: string) => {
|
||||
return service.Get('/api/oauth/get_device',
|
||||
{
|
||||
params: {
|
||||
user_id: userId,
|
||||
},
|
||||
meta: {
|
||||
ignoreToken: true,
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
@@ -30,6 +30,7 @@ import gitee from "@/assets/svgs/gitee.svg";
|
||||
import {generateClientId} from "@/api/oauth/wechat.ts";
|
||||
import {getQQUrl} from "@/api/oauth/qq.ts";
|
||||
import {useDebounceFn} from "@vueuse/core";
|
||||
import {getUserDevice} from "@/api/oauth";
|
||||
|
||||
const router = useRouter();
|
||||
const {t} = useI18n();
|
||||
@@ -109,7 +110,7 @@ function openGithubUrl() {
|
||||
const iLeft = (window.screen.width - 10 - iWidth) / 2; //获得窗口的水平位置;
|
||||
window.open(githubRedirectUrl.value, 'newwindow', 'height=' + iHeight + ',innerHeight=' + iHeight + ',width=' + iWidth + ',innerWidth=' + iWidth + ',top=' + iTop + ',left=' + iLeft + ',toolbar=no,menubar=no,scrollbars=auto,resizable=no,location=no,status=no');
|
||||
|
||||
const messageHandler = (e: any) => {
|
||||
const messageHandler = async (e: any) => {
|
||||
if (typeof e.data === 'string') {
|
||||
const data: any = JSON.parse(e.data);
|
||||
if (data.code === 0 && data.data) {
|
||||
@@ -119,6 +120,7 @@ function openGithubUrl() {
|
||||
user.user.refreshToken = refresh_token;
|
||||
user.user.uid = uid;
|
||||
user.user.expiresAt = expires_at;
|
||||
await getUserDevice(uid);
|
||||
message.success(t('login.loginSuccess'));
|
||||
window.removeEventListener("message", messageHandler);
|
||||
setTimeout(() => {
|
||||
@@ -151,7 +153,7 @@ function openGiteeUrl() {
|
||||
window.open(giteeRedirectUrl.value, '_blank', 'height=' + iHeight + ',innerHeight=' + iHeight + ',width=' + iWidth + ',innerWidth=' + iWidth + ',top=' + iTop + ',left=' + iLeft + ',toolbar=no,menubar=no,scrollbars=auto,resizable=no,location=no,status=no');
|
||||
|
||||
|
||||
const messageHandler = (e: any) => {
|
||||
const messageHandler = async (e: any) => {
|
||||
if (typeof e.data === 'string') {
|
||||
const data: any = JSON.parse(e.data);
|
||||
if (data.code === 0 && data.data) {
|
||||
@@ -161,6 +163,7 @@ function openGiteeUrl() {
|
||||
user.user.refreshToken = refresh_token;
|
||||
user.user.uid = uid;
|
||||
user.user.expiresAt = expires_at;
|
||||
await getUserDevice(uid);
|
||||
message.success(t('login.loginSuccess'));
|
||||
window.removeEventListener("message", messageHandler);
|
||||
setTimeout(() => {
|
||||
@@ -191,7 +194,7 @@ function openQQUrl() {
|
||||
const iLeft = (window.screen.width - 10 - iWidth) / 2; //获得窗口的水平位置;
|
||||
window.open(qqRedirectUrl.value, 'newwindow', 'height=' + iHeight + ',innerHeight=' + iHeight + ',width=' + iWidth + ',innerWidth=' + iWidth + ',top=' + iTop + ',left=' + iLeft + ',toolbar=no,menubar=no,scrollbars=auto,resizable=no,location=no,status=no');
|
||||
|
||||
const messageHandler = (e: any) => {
|
||||
const messageHandler = async (e: any) => {
|
||||
if (typeof e.data === 'string') {
|
||||
const data: any = JSON.parse(e.data);
|
||||
if (data.code === 0 && data.data) {
|
||||
@@ -201,6 +204,7 @@ function openQQUrl() {
|
||||
user.user.refreshToken = refresh_token;
|
||||
user.user.uid = uid;
|
||||
user.user.expiresAt = expires_at;
|
||||
await getUserDevice(uid);
|
||||
message.success(t('login.loginSuccess'));
|
||||
window.removeEventListener("message", messageHandler);
|
||||
setTimeout(() => {
|
||||
|
@@ -63,6 +63,7 @@ import logo from "@/assets/svgs/logo-schisandra.svg";
|
||||
import useWebSocket from "@/utils/websocket/websocket.ts";
|
||||
import useStore from "@/store";
|
||||
import {message} from "ant-design-vue";
|
||||
import {getUserDevice} from "@/api/oauth";
|
||||
|
||||
const {t} = useI18n();
|
||||
|
||||
@@ -126,7 +127,7 @@ onMounted(async () => {
|
||||
await getQrCode();
|
||||
open();
|
||||
// 注册消息接收处理函数
|
||||
on('message', (data: any) => {
|
||||
on('message', async (data: any) => {
|
||||
if (data.code === 0 && data.data) {
|
||||
const user = useStore().user;
|
||||
const {access_token, refresh_token, uid, expires_at} = data.data;
|
||||
@@ -135,6 +136,7 @@ onMounted(async () => {
|
||||
user.user.uid = uid;
|
||||
user.user.expiresAt = expires_at;
|
||||
status.value = 'scanned';
|
||||
await getUserDevice(uid);
|
||||
message.success(t('login.loginSuccess'));
|
||||
setTimeout(() => {
|
||||
router.push('/main');
|
||||
@@ -143,6 +145,7 @@ onMounted(async () => {
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
onUnmounted(async () => {
|
||||
close(true);
|
||||
});
|
||||
|
@@ -30,6 +30,7 @@ import gitee from "@/assets/svgs/gitee.svg";
|
||||
import {generateClientId} from "@/api/oauth/wechat.ts";
|
||||
import {getQQUrl} from "@/api/oauth/qq.ts";
|
||||
import {useDebounceFn} from "@vueuse/core";
|
||||
import {getUserDevice} from "@/api/oauth";
|
||||
|
||||
const router = useRouter();
|
||||
const {t} = useI18n();
|
||||
@@ -110,7 +111,7 @@ function openGithubUrl() {
|
||||
const iLeft = (window.screen.width - 10 - iWidth) / 2; //获得窗口的水平位置;
|
||||
window.open(githubRedirectUrl.value, 'newwindow', 'height=' + iHeight + ',innerHeight=' + iHeight + ',width=' + iWidth + ',innerWidth=' + iWidth + ',top=' + iTop + ',left=' + iLeft + ',toolbar=no,menubar=no,scrollbars=auto,resizable=no,location=no,status=no');
|
||||
|
||||
const messageHandler = (e: any) => {
|
||||
const messageHandler = async (e: any) => {
|
||||
if (typeof e.data === 'string') {
|
||||
const data: any = JSON.parse(e.data);
|
||||
if (data.code === 0 && data.data) {
|
||||
@@ -120,6 +121,7 @@ function openGithubUrl() {
|
||||
user.user.refreshToken = refresh_token;
|
||||
user.user.uid = uid;
|
||||
user.user.expiresAt = expires_at;
|
||||
await getUserDevice(uid);
|
||||
message.success(t('login.loginSuccess'));
|
||||
window.removeEventListener("message", messageHandler);
|
||||
setTimeout(() => {
|
||||
@@ -151,7 +153,7 @@ function openGiteeUrl() {
|
||||
window.open(giteeRedirectUrl.value, '_blank', 'height=' + iHeight + ',innerHeight=' + iHeight + ',width=' + iWidth + ',innerWidth=' + iWidth + ',top=' + iTop + ',left=' + iLeft + ',toolbar=no,menubar=no,scrollbars=auto,resizable=no,location=no,status=no');
|
||||
|
||||
|
||||
const messageHandler = (e: any) => {
|
||||
const messageHandler = async (e: any) => {
|
||||
if (typeof e.data === 'string') {
|
||||
const data: any = JSON.parse(e.data);
|
||||
if (data.code === 0 && data.data) {
|
||||
@@ -161,6 +163,7 @@ function openGiteeUrl() {
|
||||
user.user.refreshToken = refresh_token;
|
||||
user.user.uid = uid;
|
||||
user.user.expiresAt = expires_at;
|
||||
await getUserDevice(uid);
|
||||
message.success(t('login.loginSuccess'));
|
||||
window.removeEventListener("message", messageHandler);
|
||||
setTimeout(() => {
|
||||
@@ -191,7 +194,7 @@ function openQQUrl() {
|
||||
const iLeft = (window.screen.width - 10 - iWidth) / 2; //获得窗口的水平位置;
|
||||
window.open(qqRedirectUrl.value, 'newwindow', 'height=' + iHeight + ',innerHeight=' + iHeight + ',width=' + iWidth + ',innerWidth=' + iWidth + ',top=' + iTop + ',left=' + iLeft + ',toolbar=no,menubar=no,scrollbars=auto,resizable=no,location=no,status=no');
|
||||
|
||||
const messageHandler = (e: any) => {
|
||||
const messageHandler = async (e: any) => {
|
||||
if (typeof e.data === 'string') {
|
||||
const data: any = JSON.parse(e.data);
|
||||
if (data.code === 0 && data.data) {
|
||||
@@ -201,6 +204,7 @@ function openQQUrl() {
|
||||
user.user.refreshToken = refresh_token;
|
||||
user.user.uid = uid;
|
||||
user.user.expiresAt = expires_at;
|
||||
await getUserDevice(uid);
|
||||
message.success(t('login.loginSuccess'));
|
||||
window.removeEventListener("message", messageHandler);
|
||||
setTimeout(() => {
|
||||
|
Reference in New Issue
Block a user