mirror of
https://github.com/yawaflua/LuckyDiamond.git
synced 2025-12-10 12:19:31 +02:00
add auth connection with backend part
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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));
|
||||
|
||||
|
||||
}
|
||||
34
luckydiamond/src/assets/js/storage/CookieStorage.js
Normal file
34
luckydiamond/src/assets/js/storage/CookieStorage.js
Normal file
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user