mirror of
https://github.com/yawaflua/LuckyDiamond.git
synced 2025-12-10 04:09:29 +02:00
Merge branch 'main' into DevelopCkutls
This commit is contained in:
@@ -13,9 +13,9 @@ import { BackendApiUrl } from '@/properties/Сonfig.js';
|
|||||||
export async function LogIn(authCode) {
|
export async function LogIn(authCode) {
|
||||||
try {
|
try {
|
||||||
const response = await Post(BackendApiUrl + "/Authorize/LogIn", { code: authCode });
|
const response = await Post(BackendApiUrl + "/Authorize/LogIn", { code: authCode });
|
||||||
console.log(response);
|
|
||||||
return response;
|
return response;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Ошибка в LogIn:', error);
|
console.error('Error in LogIn:', error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,41 +1,73 @@
|
|||||||
export async function Post(url = "", data = {}) {
|
import { BackendApiUrl } from '@/properties/Сonfig.js';
|
||||||
|
|
||||||
// Default options are marked with *
|
|
||||||
|
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"
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
console.log("Fetch error:", response.status);
|
||||||
|
}
|
||||||
|
|
||||||
|
return await response.json();
|
||||||
|
} catch (error) {
|
||||||
|
console.log("Fetch error:", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function GetCurrentMoney(authToken, searchToken) {
|
||||||
|
|
||||||
|
const data = {
|
||||||
|
AUTHTOKEN: authToken,
|
||||||
|
SearchToken: searchToken
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
const response = await fetch(`${BackendApiUrl}/Payment/GetCurrentMoney`, {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
body: JSON.stringify(data),
|
||||||
|
redirect: "follow"
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
console.log("Fetch error:", response.status);
|
||||||
|
}
|
||||||
|
|
||||||
|
return await response.json();
|
||||||
|
} catch (error) {
|
||||||
|
console.log("Fetch error:", error);
|
||||||
|
}
|
||||||
// try {
|
// try {
|
||||||
// const response = await fetch(url, {
|
// const response = await fetch(`${BackendApiUrl}/Payment/GetCurrentMoney`, {
|
||||||
// method: "POST",
|
// method: 'GET',
|
||||||
// headers: {
|
// redirect: 'follow',
|
||||||
// "Content-Type": "application/json",
|
// headers: {
|
||||||
// },
|
// 'AUTHTOKEN': authToken,
|
||||||
// redirect: "follow",
|
// 'SearchToken': searchToken
|
||||||
// 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) {
|
||||||
|
// throw new Error(`HTTP error! status: ${response.status}`);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
var myHeaders = new Headers();
|
// const data = await response.json();
|
||||||
myHeaders.append("Content-Type", "application/json");
|
// console.log(data);
|
||||||
|
// return data;
|
||||||
var raw = JSON.stringify(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;
|
||||||
|
}
|
||||||
@@ -1,8 +1,109 @@
|
|||||||
|
|
||||||
|
<script>
|
||||||
|
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 {
|
||||||
|
SetCookie,
|
||||||
|
GetCookie,
|
||||||
|
DeleteAllCookie,
|
||||||
|
} from "@/assets/js/storage/CookieStorage.js";
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: "Header-Element-page",
|
||||||
|
methods: {
|
||||||
|
logout() {
|
||||||
|
this.auth = false;
|
||||||
|
this.balance = 0;
|
||||||
|
DeleteAllCookie();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
balance: 0,
|
||||||
|
auth: false,
|
||||||
|
imageUrl: "https://visage.surgeplay.com/face/55/",
|
||||||
|
userName: "",
|
||||||
|
};
|
||||||
|
},
|
||||||
|
created() {
|
||||||
|
try {
|
||||||
|
let authCode = this.$route.query.code;
|
||||||
|
|
||||||
|
if (authCode) {
|
||||||
|
LogIn(authCode)
|
||||||
|
.then((response) => {
|
||||||
|
console.log("Auth Data:", response);
|
||||||
|
SetCookie("UserId", response.userId);
|
||||||
|
SetCookie("SpUserName", response.spUserName);
|
||||||
|
SetCookie("AUTHTOKEN", response.authtoken);
|
||||||
|
SetCookie("SearchToken", response.searchToken);
|
||||||
|
|
||||||
|
this.imageUrl = this.imageUrl + `${response.spUserName}.png`;
|
||||||
|
this.userName = response.spUserName;
|
||||||
|
this.auth = true;
|
||||||
|
GetCurrentMoney(GetCookie("AUTHTOKEN"), GetCookie("SearchToken"))
|
||||||
|
.then((response) => {
|
||||||
|
this.balance = response.currentMoney;
|
||||||
|
console.log(response);
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.error(error);
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
let currentUserName = GetCookie("SpUserName");
|
||||||
|
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;
|
||||||
|
this.balance = 0;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
let currentUserName = GetCookie("SpUserName");
|
||||||
|
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;
|
||||||
|
this.balance = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Auth Code error:", error);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
|
</script>
|
||||||
<template>
|
<template>
|
||||||
<header class="header">
|
<header class="header">
|
||||||
<div class="header__content">
|
<div class="header__content">
|
||||||
<div class="header__logo">
|
<div class="header__logo">
|
||||||
<img src="../assets/logo.svg" alt="">
|
<img src="../assets/logo.svg" alt="" />
|
||||||
</div>
|
</div>
|
||||||
<div class="header__nav">
|
<div class="header__nav">
|
||||||
<nav>
|
<nav>
|
||||||
@@ -14,7 +115,11 @@
|
|||||||
<div class="header__balance">
|
<div class="header__balance">
|
||||||
<div class="header__content--balance">
|
<div class="header__content--balance">
|
||||||
<div class="header__card--balance">
|
<div class="header__card--balance">
|
||||||
<h2><img src="../assets/icons-header/diamond-ore-icon.png">{{ balance }}</h2>
|
<h2>
|
||||||
|
<img src="../assets/icons-header/diamond-ore-icon.png" />{{
|
||||||
|
balance
|
||||||
|
}}
|
||||||
|
</h2>
|
||||||
</div>
|
</div>
|
||||||
<div class="header__btn--wallet">
|
<div class="header__btn--wallet">
|
||||||
<a href="">кошелёк</a>
|
<a href="">кошелёк</a>
|
||||||
@@ -22,58 +127,35 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="header__auth--discord">
|
<div class="header__auth--discord">
|
||||||
<!-- <div v-if="auth" class="header__card--discord">
|
<div v-if="auth" class="header__card--discord">
|
||||||
<div class="discord__card--name">
|
<div class="discord__card--name">
|
||||||
<h2>Artemka</h2>
|
<h2>{{ userName }}</h2>
|
||||||
<a href="#" @click="auth = false">Выход<span><img src="../assets/icons-header/exit-icon.png"></span></a>
|
<a href="#" @click="logout"
|
||||||
|
>Выход<span
|
||||||
|
><img src="../assets/icons-header/exit-icon.png" /></span
|
||||||
|
></a>
|
||||||
</div>
|
</div>
|
||||||
<img src="../assets/icons-test/person-icon.svg" alt="test-ico">
|
<img :src="imageUrl" alt="test-ico" />
|
||||||
</div> -->
|
<!-- <img src="../assets/icons-test/person-icon.svg" alt="test-ico"> -->
|
||||||
<!-- <div v-else class="header__card--auth"> -->
|
</div>
|
||||||
<div class="header__card--auth">
|
<div v-else class="header__card--auth">
|
||||||
|
<!-- <div class="header__card--auth"> -->
|
||||||
<div class="auth__card--content">
|
<div class="auth__card--content">
|
||||||
<a href="https://discord.com/api/oauth2/authorize?client_id=1148644854797176932&redirect_uri=https%3A%2F%2Flucky-diamond.vercel.app&response_type=code&scope=identify" @click="auth = true"><span><img width="30" height="30" src="../assets/icons-header/discord-icon.svg"></span>Вход</a>
|
<a
|
||||||
|
href="https://discord.com/api/oauth2/authorize?client_id=1148644854797176932&redirect_uri=https%3A%2F%2Flucky-diamond.vercel.app&response_type=code&scope=identify"
|
||||||
|
@click="auth = true"
|
||||||
|
><span
|
||||||
|
><img
|
||||||
|
width="30"
|
||||||
|
height="30"
|
||||||
|
src="../assets/icons-header/discord-icon.svg" /></span
|
||||||
|
>Вход</a
|
||||||
|
>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
|
||||||
import '@/assets/css/ComponentsStyles/header.css'
|
|
||||||
import { LogIn } from '@/assets/js/authentication/AuthService.js';
|
|
||||||
|
|
||||||
export default {
|
|
||||||
name: 'Header-Element-page',
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
balance: 25000,
|
|
||||||
auth: false,
|
|
||||||
route: ''
|
|
||||||
}
|
|
||||||
},
|
|
||||||
mounted() {
|
|
||||||
this.route = this.$route.name
|
|
||||||
},
|
|
||||||
created() {
|
|
||||||
try {
|
|
||||||
let authCode = this.$route.query.code;
|
|
||||||
console.log('Auth Code:', authCode);
|
|
||||||
|
|
||||||
if (authCode) {
|
|
||||||
const data = LogIn(authCode);
|
|
||||||
console.log('Auth Data:', data);
|
|
||||||
} else {
|
|
||||||
console.log('Auth Code отсутствует');
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Ошибка при аутентификации:', error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
Reference in New Issue
Block a user