DmitrMakeev commited on
Commit
943ecfb
·
verified ·
1 Parent(s): bdd6051

Update user.html

Browse files
Files changed (1) hide show
  1. user.html +33 -78
user.html CHANGED
@@ -25,88 +25,43 @@
25
  </style>
26
  </head>
27
  <body>
28
- <div class="vkid-container">
29
- <script src="https://unpkg.com/@vkid/sdk@<3.0.0/dist-sdk/umd/index.js"></script>
30
- <script type="text/javascript">
31
- if ("VKIDSDK" in window) {
32
- const VKID = window.VKIDSDK;
33
 
34
- VKID.Config.init({
35
- "app": 52295022,
36
- "redirectUrl": "https://diamonik7777-up-fail.hf.space/pages",
37
- "source": VKID.ConfigSource.LOWCODE,
38
- });
39
 
40
- const oneTap = new VKID.OneTap();
41
 
42
- oneTap.render({
43
- "container": document.currentScript.parentElement,
44
- "showAlternativeLogin": true,
45
- "styles": {
46
- "width": 360
47
- },
48
- "oauthList": [
49
- "ok_ru",
50
- "mail_ru"
51
- ]
52
- })
53
- .on(VKID.WidgetEvents.ERROR, vkidOnError)
54
- .on(VKID.OneTapInternalEvents.LOGIN_SUCCESS, function (payload) {
55
- const code = payload.code;
56
- const deviceId = payload.device_id;
57
 
58
- VKID.Auth.exchangeCode(code, deviceId)
59
- .then(vkidOnSuccess)
60
- .catch(vkidOnError);
61
- });
62
- }
63
-
64
- function vkidOnSuccess(data) {
65
- const accessToken = data.access_token;
66
- localStorage.setItem('vkidAccessToken', accessToken);
67
- console.log('Access Token:', accessToken);
68
- // Используем токен для выполнения запросов к API ВКонтакте
69
- getVkUserInfo(accessToken);
70
- }
71
 
72
- function vkidOnError(error) {
73
- console.error('VKID Error:', error);
74
- }
75
-
76
- function getVkUserInfo(token) {
77
- const url = `https://api.vk.com/method/users.get?v=5.131&access_token=${token}`;
78
- fetch(url)
79
- .then(response => response.json())
80
- .then(data => {
81
- if (data.response && data.response.length > 0) {
82
- const userId = data.response[0].id;
83
- console.log('User ID:', userId);
84
- // Используем полученный ID пользователя для дальнейших действий
85
- } else {
86
- console.error('Failed to get user info:', data);
87
- }
88
- })
89
- .catch(error => {
90
- console.error('Error:', error);
91
- });
92
- }
93
-
94
- // Открытие окна авторизации в той же вкладке
95
- function openAuthWindow() {
96
- const authUrl = VKID.Auth.getAuthUrl();
97
- window.open(authUrl, '_self');
98
- }
99
-
100
- // Проверка авторизации при загрузке страницы
101
- window.onload = function() {
102
- const accessToken = localStorage.getItem('vkidAccessToken');
103
- if (!accessToken) {
104
- openAuthWindow();
105
- } else {
106
- getVkUserInfo(accessToken);
107
- }
108
- };
109
- </script>
110
- </div>
111
  </body>
112
  </html>
 
25
  </style>
26
  </head>
27
  <body>
28
+ <div>
29
+ <script src="https://unpkg.com/@vkid/sdk@<3.0.0/dist-sdk/umd/index.js"></script>
30
+ <script type="text/javascript">
31
+ if ("VKIDSDK" in window) {
32
+ const VKID = window.VKIDSDK;
33
 
34
+ VKID.Config.init({
35
+ "app": 52295022,
36
+ "redirectUrl": "https://dmtuit-psy-vk.hf.space/pages",
37
+ "source": VKID.ConfigSource.LOWCODE,
38
+ });
39
 
40
+ const floatingOneTap = new VKID.FloatingOneTap();
41
 
42
+ floatingOneTap.render({
43
+ "appName": "Конструктор приложений ВК",
44
+ "showAlternativeLogin": true
45
+ })
46
+ .on(VKID.WidgetEvents.ERROR, vkidOnError)
47
+ .on(VKID.FloatingOneTapInternalEvents.LOGIN_SUCCESS, function (payload) {
48
+ const code = payload.code;
49
+ const deviceId = payload.device_id;
 
 
 
 
 
 
 
50
 
51
+ VKID.Auth.exchangeCode(code, deviceId)
52
+ .then(vkidOnSuccess)
53
+ .catch(vkidOnError);
54
+ });
55
+ }
 
 
 
 
 
 
 
 
56
 
57
+ function vkidOnSuccess(data) {
58
+ // Обработка полученного результата
59
+ }
60
+
61
+ function vkidOnError(error) {
62
+ // Обработка ошибки
63
+ }
64
+ </script>
65
+ </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
  </body>
67
  </html>