From e516edafdcc5c82c99c5256280bb6d2e739b0d8a Mon Sep 17 00:00:00 2001 From: Hepatica Date: Sat, 2 Dec 2023 02:27:30 +0100 Subject: [PATCH 01/23] add auth connection with backend part --- .../assets/js/authentication/AuthService.js | 4 +- .../src/assets/js/rest/RestMethods.js | 74 ++++++------ .../src/assets/js/storage/CookieStorage.js | 34 ++++++ .../src/components/HeaderComponent.vue | 106 +++++++++++++----- luckydiamond/src/properties/Сonfig.js | 4 +- 5 files changed, 160 insertions(+), 62 deletions(-) create mode 100644 luckydiamond/src/assets/js/storage/CookieStorage.js diff --git a/luckydiamond/src/assets/js/authentication/AuthService.js b/luckydiamond/src/assets/js/authentication/AuthService.js index 9c64718..ba2ca16 100644 --- a/luckydiamond/src/assets/js/authentication/AuthService.js +++ b/luckydiamond/src/assets/js/authentication/AuthService.js @@ -13,9 +13,9 @@ import { BackendApiUrl } from '@/properties/Сonfig.js'; export async function LogIn(authCode) { try { const response = await Post(BackendApiUrl + "/Authorize/LogIn", { code: authCode }); - console.log(response); + return response; } catch (error) { - console.error('Ошибка в LogIn:', error); + console.error('Error in LogIn:', error); } } \ No newline at end of file diff --git a/luckydiamond/src/assets/js/rest/RestMethods.js b/luckydiamond/src/assets/js/rest/RestMethods.js index 2bdb16c..8afc9b2 100644 --- a/luckydiamond/src/assets/js/rest/RestMethods.js +++ b/luckydiamond/src/assets/js/rest/RestMethods.js @@ -1,41 +1,49 @@ +import { BackendApiUrl } from '@/properties/Сonfig.js'; + + export async function Post(url = "", data = {}) { + try { + const response = await fetch(url, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify(data), + redirect: "follow" + }); - // Default options are marked with * - // try { - // const response = await fetch(url, { - // method: "POST", - // headers: { - // "Content-Type": "application/json", - // }, - // redirect: "follow", - // referrerPolicy: "no-referrer", - // body: JSON.stringify(data), - // }); - // if (!response.ok) { - // console.log("Fetch error:", response.status); - // } - // return await response.json(); - // } catch (error) { - // console.log("Fetch error:", error); - // } + if (!response.ok) { + console.log("Fetch error:", response.status); + } - var myHeaders = new Headers(); - myHeaders.append("Content-Type", "application/json"); + return await response.json(); + } catch (error) { + console.log("Fetch error:", error); + } +} - var raw = JSON.stringify(data); +export async function GetCurrentMoney(authToken) { + + try { + const response = await fetch(`${BackendApiUrl}/Payment/GetCurrentMoney`, { + method: 'GET', + headers: { + 'AuthToken': authToken, + } + }); + + if (!response.ok) { + throw new Error(`HTTP error! status: ${response.status}`); + } + + const data = await response.json(); + console.log(data); // Здесь вы можете обработать полученные данные + return data; + } catch (error) { + console.error('There was a problem with the fetch operation:', error); + } +} - var requestOptions = { - method: 'POST', - headers: myHeaders, - body: raw, - redirect: 'follow' - }; - - fetch(url, requestOptions) - .then(response => response.text()) - .then(result => console.log(result)) - .catch(error => console.log('error', error)); -} \ No newline at end of file diff --git a/luckydiamond/src/assets/js/storage/CookieStorage.js b/luckydiamond/src/assets/js/storage/CookieStorage.js new file mode 100644 index 0000000..b28fdde --- /dev/null +++ b/luckydiamond/src/assets/js/storage/CookieStorage.js @@ -0,0 +1,34 @@ +export function SetCookie(name, value, years = 10) { + var expires = ""; + if (value) { + var date = new Date(); + date.setTime(date.getTime() + (years * 365 * 24 * 60 * 60 * 1000)); + expires = "; expires=" + date.toUTCString(); + } + document.cookie = name + "=" + (value || "") + expires + "; path=/"; +} + +export function DeleteCookie(name) { + document.cookie = name + '=; expires=Thu, 01 Jan 1970 00:00:01 GMT; path=/;'; +} + +export function DeleteAllCookie() { + const cookies = document.cookie.split(';'); + + for (let cookie of cookies) { + const eqPos = cookie.indexOf('='); + const name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie; + document.cookie = name + '=; expires=Thu, 01 Jan 1970 00:00:01 GMT; path=/;'; + } +} + +export function GetCookie(name) { + var nameEQ = name + "="; + var ca = document.cookie.split(';'); + for (var i = 0; i < ca.length; i++) { + var c = ca[i]; + while (c.charAt(0) == ' ') c = c.substring(1, c.length); + if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length); + } + return null; +} \ No newline at end of file diff --git a/luckydiamond/src/components/HeaderComponent.vue b/luckydiamond/src/components/HeaderComponent.vue index d5ed1b3..46048b5 100644 --- a/luckydiamond/src/components/HeaderComponent.vue +++ b/luckydiamond/src/components/HeaderComponent.vue @@ -1,37 +1,77 @@ \ No newline at end of file diff --git a/luckydiamond/src/properties/Сonfig.js b/luckydiamond/src/properties/Сonfig.js index d5d37dd..16a65c1 100644 --- a/luckydiamond/src/properties/Сonfig.js +++ b/luckydiamond/src/properties/Сonfig.js @@ -1,2 +1,2 @@ -export const BackendApiUrl = 'https://spsystemcore20231122004605.azurewebsites.net/api'; -// export const BackendApiUrl = 'https://localhost:7062/api'; \ No newline at end of file +// export const BackendApiUrl = 'https://spsystemcore20231122004605.azurewebsites.net/api'; +export const BackendApiUrl = 'https://localhost:7062/api'; \ No newline at end of file From b4af9349222d2a75244e1abe0fbceb6b9f8c0d26 Mon Sep 17 00:00:00 2001 From: Hepatica Date: Sat, 2 Dec 2023 02:29:48 +0100 Subject: [PATCH 02/23] Change backend url for testing --- luckydiamond/src/properties/Сonfig.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/luckydiamond/src/properties/Сonfig.js b/luckydiamond/src/properties/Сonfig.js index 16a65c1..d5d37dd 100644 --- a/luckydiamond/src/properties/Сonfig.js +++ b/luckydiamond/src/properties/Сonfig.js @@ -1,2 +1,2 @@ -// export const BackendApiUrl = 'https://spsystemcore20231122004605.azurewebsites.net/api'; -export const BackendApiUrl = 'https://localhost:7062/api'; \ No newline at end of file +export const BackendApiUrl = 'https://spsystemcore20231122004605.azurewebsites.net/api'; +// export const BackendApiUrl = 'https://localhost:7062/api'; \ No newline at end of file From 40e369ea1208b27d1e0a1ee9934a03142af95392 Mon Sep 17 00:00:00 2001 From: Hepatica Date: Sat, 2 Dec 2023 02:32:53 +0100 Subject: [PATCH 03/23] change comment line --- luckydiamond/src/components/HeaderComponent.vue | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/luckydiamond/src/components/HeaderComponent.vue b/luckydiamond/src/components/HeaderComponent.vue index 46048b5..92a5385 100644 --- a/luckydiamond/src/components/HeaderComponent.vue +++ b/luckydiamond/src/components/HeaderComponent.vue @@ -48,15 +48,15 @@ export default { } else { let currentUserName = GetCookie("SpUserName"); - let currentMoney = GetCurrentMoney( - "2405bf72008f835c9f5b336a84d3efbd7a742b828ca41fcaab1c40ca842e6425" - ); + // let currentMoney = GetCurrentMoney( + // "2405bf72008f835c9f5b336a84d3efbd7a742b828ca41fcaab1c40ca842e6425" + // ); // let currentMoney = GetCurrentMoney(GetCookie("AuthToken")); if (currentUserName) { this.imageUrl = this.imageUrl + `${currentUserName}.png`; this.auth = true; - this.balance = currentMoney; + // this.balance = currentMoney; } else { this.auth = false; } From 963e5638556c136376b3311570d034301fbe62b1 Mon Sep 17 00:00:00 2001 From: Hepatica Date: Sat, 2 Dec 2023 02:41:30 +0100 Subject: [PATCH 04/23] add no cors to post request --- luckydiamond/src/assets/js/rest/RestMethods.js | 1 + luckydiamond/src/components/HeaderComponent.vue | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/luckydiamond/src/assets/js/rest/RestMethods.js b/luckydiamond/src/assets/js/rest/RestMethods.js index 8afc9b2..d194f63 100644 --- a/luckydiamond/src/assets/js/rest/RestMethods.js +++ b/luckydiamond/src/assets/js/rest/RestMethods.js @@ -5,6 +5,7 @@ export async function Post(url = "", data = {}) { try { const response = await fetch(url, { method: "POST", + mode: 'no-cors', headers: { "Content-Type": "application/json", }, diff --git a/luckydiamond/src/components/HeaderComponent.vue b/luckydiamond/src/components/HeaderComponent.vue index 92a5385..85fed4a 100644 --- a/luckydiamond/src/components/HeaderComponent.vue +++ b/luckydiamond/src/components/HeaderComponent.vue @@ -2,7 +2,7 @@ import "@/assets/css/ComponentsStyles/header.css"; // import { GetAuthCodeFromCurrentPath } from '@/assets/js/authentication/LoggingMiddleware.js'; import { LogIn } from "@/assets/js/authentication/AuthService.js"; -import { GetCurrentMoney } from "@/assets/js/rest/RestMethods.js"; +// import { GetCurrentMoney } from "@/assets/js/rest/RestMethods.js"; import { SetCookie, GetCookie, From 184cb3d34a60cd89333c3360fd6a284830c903cc Mon Sep 17 00:00:00 2001 From: Hepatica Date: Sat, 2 Dec 2023 03:16:07 +0100 Subject: [PATCH 05/23] delete mods --- luckydiamond/src/assets/js/rest/RestMethods.js | 1 - 1 file changed, 1 deletion(-) diff --git a/luckydiamond/src/assets/js/rest/RestMethods.js b/luckydiamond/src/assets/js/rest/RestMethods.js index d194f63..8afc9b2 100644 --- a/luckydiamond/src/assets/js/rest/RestMethods.js +++ b/luckydiamond/src/assets/js/rest/RestMethods.js @@ -5,7 +5,6 @@ export async function Post(url = "", data = {}) { try { const response = await fetch(url, { method: "POST", - mode: 'no-cors', headers: { "Content-Type": "application/json", }, From 152fb6f0eee8f11f01b2358327f7e1ecc5f51df1 Mon Sep 17 00:00:00 2001 From: Hepatica Date: Sat, 2 Dec 2023 03:21:15 +0100 Subject: [PATCH 06/23] change json return value --- luckydiamond/src/components/HeaderComponent.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/luckydiamond/src/components/HeaderComponent.vue b/luckydiamond/src/components/HeaderComponent.vue index 85fed4a..d1b53cd 100644 --- a/luckydiamond/src/components/HeaderComponent.vue +++ b/luckydiamond/src/components/HeaderComponent.vue @@ -35,7 +35,7 @@ export default { console.log("Auth Data:", response); SetCookie("UserId", response.userId); SetCookie("SpUserName", response.spUserName); - SetCookie("AuthToken", response.authToken); + SetCookie("AUTHTOKEN", response.authToken); SetCookie("SearchToken", response.searchToken); this.imageUrl = this.imageUrl + `${response.spUserName}.png`; From c5115855085bc39a2481edaceaea755cbd7f5eb4 Mon Sep 17 00:00:00 2001 From: Hepatica Date: Sat, 2 Dec 2023 03:24:41 +0100 Subject: [PATCH 07/23] change json authtoken value --- luckydiamond/src/components/HeaderComponent.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/luckydiamond/src/components/HeaderComponent.vue b/luckydiamond/src/components/HeaderComponent.vue index d1b53cd..f93eee1 100644 --- a/luckydiamond/src/components/HeaderComponent.vue +++ b/luckydiamond/src/components/HeaderComponent.vue @@ -35,7 +35,7 @@ export default { console.log("Auth Data:", response); SetCookie("UserId", response.userId); SetCookie("SpUserName", response.spUserName); - SetCookie("AUTHTOKEN", response.authToken); + SetCookie("AUTHTOKEN", response.authtoken); SetCookie("SearchToken", response.searchToken); this.imageUrl = this.imageUrl + `${response.spUserName}.png`; From 2ea6de645a022864634cfbc81999c7273ee935eb Mon Sep 17 00:00:00 2001 From: Hepatica Date: Sat, 2 Dec 2023 05:10:45 +0100 Subject: [PATCH 08/23] add get money funcs --- .../src/assets/js/rest/RestMethods.js | 29 ++++++++++--------- .../src/components/HeaderComponent.vue | 12 ++++++-- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/luckydiamond/src/assets/js/rest/RestMethods.js b/luckydiamond/src/assets/js/rest/RestMethods.js index 8afc9b2..c835d8c 100644 --- a/luckydiamond/src/assets/js/rest/RestMethods.js +++ b/luckydiamond/src/assets/js/rest/RestMethods.js @@ -22,25 +22,26 @@ export async function Post(url = "", data = {}) { } } -export async function GetCurrentMoney(authToken) { +export async function GetCurrentMoney(authToken, searchToken) { try { - const response = await fetch(`${BackendApiUrl}/Payment/GetCurrentMoney`, { - method: 'GET', - headers: { - 'AuthToken': authToken, - } - }); - - if (!response.ok) { - throw new Error(`HTTP error! status: ${response.status}`); + const response = await fetch(`${BackendApiUrl}/Payment/GetCurrentMoney`, { + method: 'GET', + headers: { + 'AUTHTOKEN': authToken, + 'SearchToken': searchToken } + }); - const data = await response.json(); - console.log(data); // Здесь вы можете обработать полученные данные - return data; + if (!response.ok) { + throw new Error(`HTTP error! status: ${response.status}`); + } + + const data = await response.json(); + console.log(data); // Здесь вы можете обработать полученные данные + return data; } catch (error) { - console.error('There was a problem with the fetch operation:', error); + console.error('There was a problem with the fetch operation:', error); } } diff --git a/luckydiamond/src/components/HeaderComponent.vue b/luckydiamond/src/components/HeaderComponent.vue index f93eee1..6459d16 100644 --- a/luckydiamond/src/components/HeaderComponent.vue +++ b/luckydiamond/src/components/HeaderComponent.vue @@ -41,13 +41,21 @@ export default { this.imageUrl = this.imageUrl + `${response.spUserName}.png`; this.userName = response.spUserName; this.auth = true; + let currentMoney = GetCurrentMoney( + GetCookie("AuthToken"), + GetCookie("SearchToken") + ); + this.balance = currentMoney; }) .catch((error) => { console.error("Auth Code error:", error); }); } else { let currentUserName = GetCookie("SpUserName"); - + let currentMoney = GetCurrentMoney( + GetCookie("AuthToken"), + GetCookie("SearchToken") + ); // let currentMoney = GetCurrentMoney( // "2405bf72008f835c9f5b336a84d3efbd7a742b828ca41fcaab1c40ca842e6425" // ); @@ -56,7 +64,7 @@ export default { if (currentUserName) { this.imageUrl = this.imageUrl + `${currentUserName}.png`; this.auth = true; - // this.balance = currentMoney; + this.balance = currentMoney; } else { this.auth = false; } From 3744f7d5ee85625530e2720b0ca5c53127224163 Mon Sep 17 00:00:00 2001 From: Hepatica Date: Sat, 2 Dec 2023 05:13:41 +0100 Subject: [PATCH 09/23] fix small bug with getting money --- luckydiamond/src/components/HeaderComponent.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/luckydiamond/src/components/HeaderComponent.vue b/luckydiamond/src/components/HeaderComponent.vue index 6459d16..6e26a1e 100644 --- a/luckydiamond/src/components/HeaderComponent.vue +++ b/luckydiamond/src/components/HeaderComponent.vue @@ -2,7 +2,7 @@ import "@/assets/css/ComponentsStyles/header.css"; // import { GetAuthCodeFromCurrentPath } from '@/assets/js/authentication/LoggingMiddleware.js'; import { LogIn } from "@/assets/js/authentication/AuthService.js"; -// import { GetCurrentMoney } from "@/assets/js/rest/RestMethods.js"; +import { GetCurrentMoney } from "@/assets/js/rest/RestMethods.js"; import { SetCookie, GetCookie, From 0d78b3bd132d1c50c21cae777221dce07db319f8 Mon Sep 17 00:00:00 2001 From: Hepatica Date: Sat, 2 Dec 2023 05:18:01 +0100 Subject: [PATCH 10/23] add no cors mod to API for getting money --- luckydiamond/src/assets/js/rest/RestMethods.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/luckydiamond/src/assets/js/rest/RestMethods.js b/luckydiamond/src/assets/js/rest/RestMethods.js index c835d8c..2c7f286 100644 --- a/luckydiamond/src/assets/js/rest/RestMethods.js +++ b/luckydiamond/src/assets/js/rest/RestMethods.js @@ -27,7 +27,9 @@ export async function GetCurrentMoney(authToken, searchToken) { try { const response = await fetch(`${BackendApiUrl}/Payment/GetCurrentMoney`, { method: 'GET', + mode: 'no-cors', headers: { + "Content-Type": "application/json", 'AUTHTOKEN': authToken, 'SearchToken': searchToken } From 59c0457f919c6702867ecffc4aa766176e60da44 Mon Sep 17 00:00:00 2001 From: Hepatica Date: Sat, 2 Dec 2023 05:29:29 +0100 Subject: [PATCH 11/23] fix bugs --- .../src/assets/js/rest/RestMethods.js | 2 +- .../src/components/HeaderComponent.vue | 30 ++++++++++++------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/luckydiamond/src/assets/js/rest/RestMethods.js b/luckydiamond/src/assets/js/rest/RestMethods.js index 2c7f286..8575d07 100644 --- a/luckydiamond/src/assets/js/rest/RestMethods.js +++ b/luckydiamond/src/assets/js/rest/RestMethods.js @@ -40,7 +40,7 @@ export async function GetCurrentMoney(authToken, searchToken) { } const data = await response.json(); - console.log(data); // Здесь вы можете обработать полученные данные + console.log(data); return data; } catch (error) { console.error('There was a problem with the fetch operation:', error); diff --git a/luckydiamond/src/components/HeaderComponent.vue b/luckydiamond/src/components/HeaderComponent.vue index 6e26a1e..9de2ea4 100644 --- a/luckydiamond/src/components/HeaderComponent.vue +++ b/luckydiamond/src/components/HeaderComponent.vue @@ -42,24 +42,32 @@ export default { this.userName = response.spUserName; this.auth = true; let currentMoney = GetCurrentMoney( - GetCookie("AuthToken"), - GetCookie("SearchToken") + response.authtoken, + response.searchToken ); - this.balance = currentMoney; + this.balance = currentMoney; }) .catch((error) => { - console.error("Auth Code error:", error); + let currentUserName = GetCookie("SpUserName"); + let currentMoney = GetCurrentMoney( + GetCookie("AUTHTOKEN"), + GetCookie("SearchToken") + ); + + if (currentUserName) { + this.imageUrl = this.imageUrl + `${currentUserName}.png`; + this.auth = true; + this.balance = currentMoney; + } else { + this.auth = false; + } }); } else { let currentUserName = GetCookie("SpUserName"); let currentMoney = GetCurrentMoney( - GetCookie("AuthToken"), - GetCookie("SearchToken") - ); - // let currentMoney = GetCurrentMoney( - // "2405bf72008f835c9f5b336a84d3efbd7a742b828ca41fcaab1c40ca842e6425" - // ); - // let currentMoney = GetCurrentMoney(GetCookie("AuthToken")); + GetCookie("AUTHTOKEN"), + GetCookie("SearchToken") + ); if (currentUserName) { this.imageUrl = this.imageUrl + `${currentUserName}.png`; From 0fa501cfeecf4730a71b8ecd6f0471f1629c3049 Mon Sep 17 00:00:00 2001 From: Hepatica Date: Sat, 2 Dec 2023 05:31:05 +0100 Subject: [PATCH 12/23] delete error label --- luckydiamond/src/components/HeaderComponent.vue | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/luckydiamond/src/components/HeaderComponent.vue b/luckydiamond/src/components/HeaderComponent.vue index 9de2ea4..078329c 100644 --- a/luckydiamond/src/components/HeaderComponent.vue +++ b/luckydiamond/src/components/HeaderComponent.vue @@ -47,7 +47,7 @@ export default { ); this.balance = currentMoney; }) - .catch((error) => { + .catch(() => { let currentUserName = GetCookie("SpUserName"); let currentMoney = GetCurrentMoney( GetCookie("AUTHTOKEN"), @@ -61,6 +61,7 @@ export default { } else { this.auth = false; } + }); } else { let currentUserName = GetCookie("SpUserName"); From 81672d7265406c73ee5b05acb2271f7b3b8c4b8b Mon Sep 17 00:00:00 2001 From: Hepatica Date: Sat, 2 Dec 2023 05:33:25 +0100 Subject: [PATCH 13/23] delete no cors --- luckydiamond/src/assets/js/rest/RestMethods.js | 1 - 1 file changed, 1 deletion(-) diff --git a/luckydiamond/src/assets/js/rest/RestMethods.js b/luckydiamond/src/assets/js/rest/RestMethods.js index 8575d07..947bd50 100644 --- a/luckydiamond/src/assets/js/rest/RestMethods.js +++ b/luckydiamond/src/assets/js/rest/RestMethods.js @@ -27,7 +27,6 @@ export async function GetCurrentMoney(authToken, searchToken) { try { const response = await fetch(`${BackendApiUrl}/Payment/GetCurrentMoney`, { method: 'GET', - mode: 'no-cors', headers: { "Content-Type": "application/json", 'AUTHTOKEN': authToken, From 38e9b34df611f4324ff110692df396e84afcec34 Mon Sep 17 00:00:00 2001 From: Hepatica Date: Sat, 2 Dec 2023 05:50:18 +0100 Subject: [PATCH 14/23] change get method --- luckydiamond/src/assets/js/rest/RestMethods.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/luckydiamond/src/assets/js/rest/RestMethods.js b/luckydiamond/src/assets/js/rest/RestMethods.js index 947bd50..a77ef43 100644 --- a/luckydiamond/src/assets/js/rest/RestMethods.js +++ b/luckydiamond/src/assets/js/rest/RestMethods.js @@ -27,8 +27,8 @@ export async function GetCurrentMoney(authToken, searchToken) { try { const response = await fetch(`${BackendApiUrl}/Payment/GetCurrentMoney`, { method: 'GET', + redirect: 'follow', headers: { - "Content-Type": "application/json", 'AUTHTOKEN': authToken, 'SearchToken': searchToken } @@ -39,7 +39,7 @@ export async function GetCurrentMoney(authToken, searchToken) { } const data = await response.json(); - console.log(data); + console.log(data); return data; } catch (error) { console.error('There was a problem with the fetch operation:', error); From 4f44fa9255e1d89268ffa81526411e1a4ed5b525 Mon Sep 17 00:00:00 2001 From: Hepatica Date: Sat, 2 Dec 2023 06:02:39 +0100 Subject: [PATCH 15/23] add no cors --- luckydiamond/src/assets/js/rest/RestMethods.js | 1 + 1 file changed, 1 insertion(+) diff --git a/luckydiamond/src/assets/js/rest/RestMethods.js b/luckydiamond/src/assets/js/rest/RestMethods.js index a77ef43..7b23c69 100644 --- a/luckydiamond/src/assets/js/rest/RestMethods.js +++ b/luckydiamond/src/assets/js/rest/RestMethods.js @@ -27,6 +27,7 @@ export async function GetCurrentMoney(authToken, searchToken) { try { const response = await fetch(`${BackendApiUrl}/Payment/GetCurrentMoney`, { method: 'GET', + mode: 'no-cors', redirect: 'follow', headers: { 'AUTHTOKEN': authToken, From cd93db0d22af5ca39069fe16cd24a1cb8f91da85 Mon Sep 17 00:00:00 2001 From: Hepatica Date: Sat, 2 Dec 2023 06:10:36 +0100 Subject: [PATCH 16/23] publish --- luckydiamond/src/assets/js/rest/RestMethods.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/luckydiamond/src/assets/js/rest/RestMethods.js b/luckydiamond/src/assets/js/rest/RestMethods.js index 7b23c69..c98b007 100644 --- a/luckydiamond/src/assets/js/rest/RestMethods.js +++ b/luckydiamond/src/assets/js/rest/RestMethods.js @@ -27,7 +27,7 @@ export async function GetCurrentMoney(authToken, searchToken) { try { const response = await fetch(`${BackendApiUrl}/Payment/GetCurrentMoney`, { method: 'GET', - mode: 'no-cors', + redirect: 'follow', headers: { 'AUTHTOKEN': authToken, From 98a39ee7631ed6f496790cdbfc5fcde8d50068b6 Mon Sep 17 00:00:00 2001 From: Hepatica Date: Sat, 2 Dec 2023 06:14:06 +0100 Subject: [PATCH 17/23] add access control --- luckydiamond/src/assets/js/rest/RestMethods.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/luckydiamond/src/assets/js/rest/RestMethods.js b/luckydiamond/src/assets/js/rest/RestMethods.js index c98b007..1bd3307 100644 --- a/luckydiamond/src/assets/js/rest/RestMethods.js +++ b/luckydiamond/src/assets/js/rest/RestMethods.js @@ -27,11 +27,11 @@ export async function GetCurrentMoney(authToken, searchToken) { try { const response = await fetch(`${BackendApiUrl}/Payment/GetCurrentMoney`, { method: 'GET', - redirect: 'follow', headers: { 'AUTHTOKEN': authToken, - 'SearchToken': searchToken + 'SearchToken': searchToken, + 'Access-Control-Allow-Origin': '*' } }); From c64b41545d5ddbd23415e8fd33ae8977a70310f1 Mon Sep 17 00:00:00 2001 From: Hepatica Date: Sat, 2 Dec 2023 06:30:55 +0100 Subject: [PATCH 18/23] Change rest method --- .../src/assets/js/rest/RestMethods.js | 45 ++++++++++++++----- 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/luckydiamond/src/assets/js/rest/RestMethods.js b/luckydiamond/src/assets/js/rest/RestMethods.js index 1bd3307..e57f1b5 100644 --- a/luckydiamond/src/assets/js/rest/RestMethods.js +++ b/luckydiamond/src/assets/js/rest/RestMethods.js @@ -24,27 +24,48 @@ export async function Post(url = "", data = {}) { export async function GetCurrentMoney(authToken, searchToken) { + const data = { + AUTHTOKEN: authToken, + SearchToken: searchToken + }; try { - const response = await fetch(`${BackendApiUrl}/Payment/GetCurrentMoney`, { - method: 'GET', - redirect: 'follow', + const response = await fetch(url, { + method: "GET", headers: { - 'AUTHTOKEN': authToken, - 'SearchToken': searchToken, - 'Access-Control-Allow-Origin': '*' - } + "Content-Type": "application/json", + }, + body: JSON.stringify(data), + redirect: "follow" }); if (!response.ok) { - throw new Error(`HTTP error! status: ${response.status}`); + console.log("Fetch error:", response.status); } - const data = await response.json(); - console.log(data); - return data; + return await response.json(); } catch (error) { - console.error('There was a problem with the fetch operation:', error); + console.log("Fetch error:", error); } + // try { + // const response = await fetch(`${BackendApiUrl}/Payment/GetCurrentMoney`, { + // method: 'GET', + // redirect: 'follow', + // headers: { + // 'AUTHTOKEN': authToken, + // 'SearchToken': searchToken + // } + // }); + + // if (!response.ok) { + // throw new Error(`HTTP error! status: ${response.status}`); + // } + + // const data = await response.json(); + // console.log(data); + // return data; + // } catch (error) { + // console.error('There was a problem with the fetch operation:', error); + // } } From 837fc2a6f320cf8aa878f5883f5f6b98cbf597b7 Mon Sep 17 00:00:00 2001 From: Hepatica Date: Sat, 2 Dec 2023 06:31:24 +0100 Subject: [PATCH 19/23] second change --- luckydiamond/src/assets/js/rest/RestMethods.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/luckydiamond/src/assets/js/rest/RestMethods.js b/luckydiamond/src/assets/js/rest/RestMethods.js index e57f1b5..69e759c 100644 --- a/luckydiamond/src/assets/js/rest/RestMethods.js +++ b/luckydiamond/src/assets/js/rest/RestMethods.js @@ -30,7 +30,7 @@ export async function GetCurrentMoney(authToken, searchToken) { }; try { const response = await fetch(url, { - method: "GET", + method: "POST", headers: { "Content-Type": "application/json", }, From 05fe9d98aef5d77bfbeb581a1fb2753ef4f2c3ac Mon Sep 17 00:00:00 2001 From: Hepatica Date: Sat, 2 Dec 2023 06:32:51 +0100 Subject: [PATCH 20/23] fix url --- luckydiamond/src/assets/js/rest/RestMethods.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/luckydiamond/src/assets/js/rest/RestMethods.js b/luckydiamond/src/assets/js/rest/RestMethods.js index 69e759c..314c58b 100644 --- a/luckydiamond/src/assets/js/rest/RestMethods.js +++ b/luckydiamond/src/assets/js/rest/RestMethods.js @@ -29,7 +29,7 @@ export async function GetCurrentMoney(authToken, searchToken) { SearchToken: searchToken }; try { - const response = await fetch(url, { + const response = await fetch(`${BackendApiUrl}/Payment/GetCurrentMoney`, { method: "POST", headers: { "Content-Type": "application/json", From 1abb58e267408d2828397a8108e9f0e7b90b9871 Mon Sep 17 00:00:00 2001 From: Hepatica Date: Sat, 2 Dec 2023 06:46:25 +0100 Subject: [PATCH 21/23] ad then events --- .../src/components/HeaderComponent.vue | 55 +++++++++++++------ 1 file changed, 39 insertions(+), 16 deletions(-) diff --git a/luckydiamond/src/components/HeaderComponent.vue b/luckydiamond/src/components/HeaderComponent.vue index 078329c..84c8e82 100644 --- a/luckydiamond/src/components/HeaderComponent.vue +++ b/luckydiamond/src/components/HeaderComponent.vue @@ -41,39 +41,62 @@ export default { this.imageUrl = this.imageUrl + `${response.spUserName}.png`; this.userName = response.spUserName; this.auth = true; - let currentMoney = GetCurrentMoney( - response.authtoken, - response.searchToken - ); - this.balance = currentMoney; + GetCurrentMoney(GetCookie("AUTHTOKEN"), GetCookie("SearchToken")) + .then((response) => { + this.balance = response.currentMoney; + console.log(response); + }) + .catch((error) => { + // Обработка ошибки + console.error(error); + }); + + // let currentMoney = GetCurrentMoney( + // response.authtoken, + // response.searchToken + // ); + // this.balance = currentMoney; }) .catch(() => { let currentUserName = GetCookie("SpUserName"); - let currentMoney = GetCurrentMoney( - GetCookie("AUTHTOKEN"), - GetCookie("SearchToken") - ); + + // let currentMoney = GetCurrentMoney( + // GetCookie("AUTHTOKEN"), + // GetCookie("SearchToken") + // ).then(response); + + GetCurrentMoney(GetCookie("AUTHTOKEN"), GetCookie("SearchToken")) + .then((response) => { + this.balance = response.currentMoney; + console.log(response); + }) + .catch((error) => { + // Обработка ошибки + console.error(error); + }); if (currentUserName) { this.imageUrl = this.imageUrl + `${currentUserName}.png`; this.auth = true; - this.balance = currentMoney; } else { this.auth = false; } - }); } else { let currentUserName = GetCookie("SpUserName"); - let currentMoney = GetCurrentMoney( - GetCookie("AUTHTOKEN"), - GetCookie("SearchToken") - ); + GetCurrentMoney(GetCookie("AUTHTOKEN"), GetCookie("SearchToken")) + .then((response) => { + this.balance = response.currentMoney; + console.log(response); + }) + .catch((error) => { + // Обработка ошибки + console.error(error); + }); if (currentUserName) { this.imageUrl = this.imageUrl + `${currentUserName}.png`; this.auth = true; - this.balance = currentMoney; } else { this.auth = false; } From 9e2a7136f4a7aea9871cf06c0b0ba876948cdb1a Mon Sep 17 00:00:00 2001 From: Hepatica Date: Sat, 2 Dec 2023 06:51:00 +0100 Subject: [PATCH 22/23] add removing balance --- luckydiamond/src/components/HeaderComponent.vue | 3 +++ 1 file changed, 3 insertions(+) diff --git a/luckydiamond/src/components/HeaderComponent.vue b/luckydiamond/src/components/HeaderComponent.vue index 84c8e82..baf969c 100644 --- a/luckydiamond/src/components/HeaderComponent.vue +++ b/luckydiamond/src/components/HeaderComponent.vue @@ -14,6 +14,7 @@ export default { methods: { logout() { this.auth = false; + this.balance = 0; DeleteAllCookie(); }, }, @@ -80,6 +81,7 @@ export default { this.auth = true; } else { this.auth = false; + this.balance = 0; } }); } else { @@ -99,6 +101,7 @@ export default { this.auth = true; } else { this.auth = false; + this.balance = 0; } } } catch (error) { From 7fb400b559e6222215608528e0477704ccd85f61 Mon Sep 17 00:00:00 2001 From: Hepatica Date: Sat, 2 Dec 2023 16:19:33 +0100 Subject: [PATCH 23/23] fix bug with money --- luckydiamond/src/components/HeaderComponent.vue | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/luckydiamond/src/components/HeaderComponent.vue b/luckydiamond/src/components/HeaderComponent.vue index baf969c..5e54ff0 100644 --- a/luckydiamond/src/components/HeaderComponent.vue +++ b/luckydiamond/src/components/HeaderComponent.vue @@ -48,36 +48,23 @@ export default { console.log(response); }) .catch((error) => { - // Обработка ошибки console.error(error); }); - - // let currentMoney = GetCurrentMoney( - // response.authtoken, - // response.searchToken - // ); - // this.balance = currentMoney; }) .catch(() => { let currentUserName = GetCookie("SpUserName"); - - // let currentMoney = GetCurrentMoney( - // GetCookie("AUTHTOKEN"), - // GetCookie("SearchToken") - // ).then(response); - GetCurrentMoney(GetCookie("AUTHTOKEN"), GetCookie("SearchToken")) .then((response) => { this.balance = response.currentMoney; console.log(response); }) .catch((error) => { - // Обработка ошибки console.error(error); }); if (currentUserName) { this.imageUrl = this.imageUrl + `${currentUserName}.png`; + this.userName = GetCookie("SpUserName"); this.auth = true; } else { this.auth = false; @@ -98,6 +85,7 @@ export default { if (currentUserName) { this.imageUrl = this.imageUrl + `${currentUserName}.png`; + this.userName = GetCookie("SpUserName"); this.auth = true; } else { this.auth = false;