Update pages.html
Browse files- pages.html +77 -23
pages.html
CHANGED
@@ -932,7 +932,11 @@ z-index: 1000; /* Убедитесь, что кнопка находится п
|
|
932 |
<body>
|
933 |
|
934 |
|
935 |
-
|
|
|
|
|
|
|
|
|
936 |
<script src="https://unpkg.com/@vkid/sdk@<3.0.0/dist-sdk/umd/index.js"></script>
|
937 |
<script type="text/javascript">
|
938 |
if ("VKIDSDK" in window) {
|
@@ -940,42 +944,92 @@ z-index: 1000; /* Убедитесь, что кнопка находится п
|
|
940 |
|
941 |
VKID.Config.init({
|
942 |
"app": 52295022,
|
943 |
-
"redirectUrl":
|
944 |
"source": VKID.ConfigSource.LOWCODE,
|
945 |
});
|
946 |
|
947 |
const oneTap = new VKID.OneTap();
|
948 |
|
949 |
-
|
950 |
-
|
951 |
-
|
952 |
-
|
953 |
-
|
954 |
-
|
955 |
-
|
956 |
-
|
957 |
-
|
958 |
-
|
959 |
-
|
960 |
-
|
961 |
-
|
962 |
-
|
963 |
-
|
964 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
965 |
}
|
966 |
-
|
967 |
function vkidOnSuccess(data) {
|
968 |
-
//
|
|
|
|
|
|
|
|
|
969 |
}
|
970 |
-
|
971 |
function vkidOnError(error) {
|
972 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
973 |
}
|
974 |
</script>
|
975 |
-
</div>
|
976 |
|
977 |
|
978 |
|
|
|
|
|
|
|
|
|
979 |
|
980 |
|
981 |
|
|
|
932 |
<body>
|
933 |
|
934 |
|
935 |
+
|
936 |
+
|
937 |
+
|
938 |
+
<div class="mod_vk" id="vkid-container"></div>
|
939 |
+
|
940 |
<script src="https://unpkg.com/@vkid/sdk@<3.0.0/dist-sdk/umd/index.js"></script>
|
941 |
<script type="text/javascript">
|
942 |
if ("VKIDSDK" in window) {
|
|
|
944 |
|
945 |
VKID.Config.init({
|
946 |
"app": 52295022,
|
947 |
+
"redirectUrl": window.location.href, // Редирект на текущую страницу
|
948 |
"source": VKID.ConfigSource.LOWCODE,
|
949 |
});
|
950 |
|
951 |
const oneTap = new VKID.OneTap();
|
952 |
|
953 |
+
// Проверка наличия токена в localStorage
|
954 |
+
const accessToken = localStorage.getItem('vkidAccessToken');
|
955 |
+
if (accessToken) {
|
956 |
+
document.getElementById('vkid-container').style.display = 'none'; // Скрыть окно входа
|
957 |
+
getVkUserInfo(accessToken); // Получить информацию о пользователе
|
958 |
+
} else {
|
959 |
+
oneTap.render({
|
960 |
+
"container": document.getElementById('vkid-container'),
|
961 |
+
"showAlternativeLogin": true,
|
962 |
+
"styles": {
|
963 |
+
"width": 360
|
964 |
+
}
|
965 |
+
})
|
966 |
+
.on(VKID.WidgetEvents.ERROR, vkidOnError)
|
967 |
+
.on(VKID.OneTapInternalEvents.LOGIN_SUCCESS, function (payload) {
|
968 |
+
const code = payload.code;
|
969 |
+
const deviceId = payload.device_id;
|
970 |
+
|
971 |
+
VKID.Auth.exchangeCode(code, deviceId)
|
972 |
+
.then(vkidOnSuccess)
|
973 |
+
.catch(vkidOnError);
|
974 |
+
});
|
975 |
+
}
|
976 |
}
|
977 |
+
|
978 |
function vkidOnSuccess(data) {
|
979 |
+
// Сохранение токена в localStorage
|
980 |
+
localStorage.setItem('vkidAccessToken', data.access_token);
|
981 |
+
|
982 |
+
// Получение информации о пользователе
|
983 |
+
getVkUserInfo(data.access_token);
|
984 |
}
|
985 |
+
|
986 |
function vkidOnError(error) {
|
987 |
+
console.error('VKID Error:', error);
|
988 |
+
}
|
989 |
+
|
990 |
+
function getVkUserInfo(token) {
|
991 |
+
// Запрос к API ВКонтакте для получения информации о пользователе
|
992 |
+
fetch('https://api.vk.com/method/users.get?v=5.131&access_token=' + token)
|
993 |
+
.then(response => response.json())
|
994 |
+
.then(data => {
|
995 |
+
if (data.response && data.response.length > 0) {
|
996 |
+
const userId = data.response[0].id;
|
997 |
+
console.log('User ID:', userId);
|
998 |
+
sendRequestWithUserId(userId); // Отправить запрос с ID пользователя
|
999 |
+
} else {
|
1000 |
+
console.error('Failed to get user info:', data);
|
1001 |
+
}
|
1002 |
+
})
|
1003 |
+
.catch(error => {
|
1004 |
+
console.error('Error getting user info:', error);
|
1005 |
+
});
|
1006 |
+
}
|
1007 |
+
|
1008 |
+
function sendRequestWithUserId(userId) {
|
1009 |
+
// Пример отправки запроса с ID пользователя
|
1010 |
+
fetch('https://your-api-endpoint.com/some-resource', {
|
1011 |
+
method: 'POST',
|
1012 |
+
headers: {
|
1013 |
+
'Content-Type': 'application/json'
|
1014 |
+
},
|
1015 |
+
body: JSON.stringify({ userId: userId })
|
1016 |
+
})
|
1017 |
+
.then(response => response.json())
|
1018 |
+
.then(data => {
|
1019 |
+
console.log('Response from API:', data);
|
1020 |
+
})
|
1021 |
+
.catch(error => {
|
1022 |
+
console.error('Error sending request:', error);
|
1023 |
+
});
|
1024 |
}
|
1025 |
</script>
|
|
|
1026 |
|
1027 |
|
1028 |
|
1029 |
+
|
1030 |
+
|
1031 |
+
|
1032 |
+
|
1033 |
|
1034 |
|
1035 |
|