ваше сообщение коммита
This commit is contained in:
@@ -1,173 +1,90 @@
|
||||
<template>
|
||||
<div class="email-connection">
|
||||
<div v-if="!showVerification" class="email-form">
|
||||
<input
|
||||
v-model="email"
|
||||
type="email"
|
||||
placeholder="Введите email"
|
||||
class="email-input"
|
||||
/>
|
||||
<button
|
||||
@click="requestCode"
|
||||
:disabled="isLoading || !isValidEmail"
|
||||
class="email-btn"
|
||||
>
|
||||
<input v-model="email" type="email" placeholder="Введите email" class="email-input" />
|
||||
<button :disabled="isLoading || !isValidEmail" class="email-btn" @click="requestCode">
|
||||
{{ isLoading ? 'Отправка...' : 'Получить код' }}
|
||||
</button>
|
||||
</div>
|
||||
<div v-else class="verification-form">
|
||||
<p class="verification-info">Код отправлен на {{ email }}</p>
|
||||
<input
|
||||
v-model="code"
|
||||
type="text"
|
||||
placeholder="Введите код"
|
||||
class="code-input"
|
||||
/>
|
||||
<button
|
||||
@click="verifyCode"
|
||||
:disabled="isLoading || !code"
|
||||
class="verify-btn"
|
||||
>
|
||||
<input v-model="code" type="text" placeholder="Введите код" class="code-input" />
|
||||
<button :disabled="isLoading || !code" class="verify-btn" @click="verifyCode">
|
||||
{{ isLoading ? 'Проверка...' : 'Подтвердить' }}
|
||||
</button>
|
||||
<button
|
||||
@click="resetForm"
|
||||
class="reset-btn"
|
||||
>
|
||||
Изменить email
|
||||
</button>
|
||||
<button class="reset-btn" @click="resetForm">Изменить email</button>
|
||||
</div>
|
||||
<div v-if="error" class="error">{{ error }}</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, computed } from 'vue';
|
||||
import axios from '@/api/axios';
|
||||
import { useAuth } from '@/composables/useAuth';
|
||||
import { ref, computed } from 'vue';
|
||||
import axios from '@/api/axios';
|
||||
import { useAuth } from '@/composables/useAuth';
|
||||
|
||||
const emit = defineEmits(['close']);
|
||||
const { linkIdentity } = useAuth();
|
||||
const emit = defineEmits(['close']);
|
||||
const { linkIdentity } = useAuth();
|
||||
|
||||
const email = ref('');
|
||||
const code = ref('');
|
||||
const error = ref('');
|
||||
const isLoading = ref(false);
|
||||
const showVerification = ref(false);
|
||||
const email = ref('');
|
||||
const code = ref('');
|
||||
const error = ref('');
|
||||
const isLoading = ref(false);
|
||||
const showVerification = ref(false);
|
||||
|
||||
const isValidEmail = computed(() => {
|
||||
return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email.value);
|
||||
});
|
||||
const isValidEmail = computed(() => {
|
||||
return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email.value);
|
||||
});
|
||||
|
||||
const requestCode = async () => {
|
||||
try {
|
||||
isLoading.value = true;
|
||||
error.value = '';
|
||||
|
||||
const response = await axios.post('/api/auth/email/request-verification', {
|
||||
email: email.value
|
||||
});
|
||||
|
||||
if (response.data.success) {
|
||||
showVerification.value = true;
|
||||
} else {
|
||||
error.value = response.data.error || 'Ошибка отправки кода';
|
||||
const requestCode = async () => {
|
||||
try {
|
||||
isLoading.value = true;
|
||||
error.value = '';
|
||||
|
||||
const response = await axios.post('/api/auth/email/request-verification', {
|
||||
email: email.value,
|
||||
});
|
||||
|
||||
if (response.data.success) {
|
||||
showVerification.value = true;
|
||||
} else {
|
||||
error.value = response.data.error || 'Ошибка отправки кода';
|
||||
}
|
||||
} catch (err) {
|
||||
error.value = err.response?.data?.error || 'Ошибка отправки кода';
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
}
|
||||
} catch (err) {
|
||||
error.value = err.response?.data?.error || 'Ошибка отправки кода';
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
const verifyCode = async () => {
|
||||
try {
|
||||
isLoading.value = true;
|
||||
error.value = '';
|
||||
|
||||
const response = await axios.post('/api/auth/email/verify', {
|
||||
email: email.value,
|
||||
code: code.value
|
||||
});
|
||||
|
||||
if (response.data.success) {
|
||||
// Связываем email с текущим пользователем
|
||||
await linkIdentity('email', email.value);
|
||||
emit('close');
|
||||
} else {
|
||||
error.value = response.data.error || 'Неверный код';
|
||||
const verifyCode = async () => {
|
||||
try {
|
||||
isLoading.value = true;
|
||||
error.value = '';
|
||||
|
||||
const response = await axios.post('/api/auth/email/verify', {
|
||||
email: email.value,
|
||||
code: code.value,
|
||||
});
|
||||
|
||||
if (response.data.success) {
|
||||
// Связываем email с текущим пользователем
|
||||
await linkIdentity('email', email.value);
|
||||
emit('close');
|
||||
} else {
|
||||
error.value = response.data.error || 'Неверный код';
|
||||
}
|
||||
} catch (err) {
|
||||
error.value = err.response?.data?.error || 'Ошибка проверки кода';
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
}
|
||||
} catch (err) {
|
||||
error.value = err.response?.data?.error || 'Ошибка проверки кода';
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
const resetForm = () => {
|
||||
email.value = '';
|
||||
code.value = '';
|
||||
error.value = '';
|
||||
showVerification.value = false;
|
||||
};
|
||||
const resetForm = () => {
|
||||
email.value = '';
|
||||
code.value = '';
|
||||
error.value = '';
|
||||
showVerification.value = false;
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.email-connection {
|
||||
padding: 20px;
|
||||
max-width: 400px;
|
||||
}
|
||||
|
||||
.email-form,
|
||||
.verification-form {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.email-input,
|
||||
.code-input {
|
||||
padding: 8px 12px;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 4px;
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
.email-btn,
|
||||
.verify-btn,
|
||||
.reset-btn {
|
||||
padding: 10px;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
font-size: 14px;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.email-btn,
|
||||
.verify-btn {
|
||||
background-color: #48bb78;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.reset-btn {
|
||||
background-color: #e2e8f0;
|
||||
color: #4a5568;
|
||||
}
|
||||
|
||||
.verification-info {
|
||||
color: #4a5568;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.error {
|
||||
color: #e53e3e;
|
||||
margin-top: 5px;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
button:disabled {
|
||||
opacity: 0.7;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<div class="telegram-connect">
|
||||
<div v-if="!showQR" class="intro">
|
||||
<p>Подключите свой аккаунт Telegram для быстрой авторизации</p>
|
||||
<button @click="startConnection" class="connect-button" :disabled="loading">
|
||||
<button class="connect-button" :disabled="loading" @click="startConnection">
|
||||
<span class="telegram-icon">📱</span>
|
||||
{{ loading ? 'Загрузка...' : 'Подключить Telegram' }}
|
||||
</button>
|
||||
@@ -10,14 +10,11 @@
|
||||
|
||||
<div v-else class="qr-section">
|
||||
<p>Отсканируйте QR-код в приложении Telegram</p>
|
||||
<div class="qr-container" v-html="qrCode"></div>
|
||||
<!-- eslint-disable-next-line vue/no-v-html -->
|
||||
<div class="qr-container" v-html="qrCode" />
|
||||
<p class="or-divider">или</p>
|
||||
<a :href="botLink" target="_blank" class="bot-link">
|
||||
Открыть бота в Telegram
|
||||
</a>
|
||||
<button @click="resetConnection" class="reset-button">
|
||||
Отмена
|
||||
</button>
|
||||
<a :href="botLink" target="_blank" class="bot-link"> Открыть бота в Telegram </a>
|
||||
<button class="reset-button" @click="resetConnection">Отмена</button>
|
||||
</div>
|
||||
|
||||
<div v-if="error" class="error">{{ error }}</div>
|
||||
@@ -25,183 +22,87 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, onMounted, onUnmounted } from 'vue';
|
||||
import axios from '@/api/axios';
|
||||
import { useAuth } from '@/composables/useAuth';
|
||||
import QRCode from 'qrcode';
|
||||
import { ref, onMounted, onUnmounted } from 'vue';
|
||||
import axios from '@/api/axios';
|
||||
import { useAuth } from '@/composables/useAuth';
|
||||
import QRCode from 'qrcode';
|
||||
|
||||
const emit = defineEmits(['close']);
|
||||
const { linkIdentity } = useAuth();
|
||||
const emit = defineEmits(['close']);
|
||||
const { linkIdentity } = useAuth();
|
||||
|
||||
const loading = ref(false);
|
||||
const error = ref('');
|
||||
const showQR = ref(false);
|
||||
const qrCode = ref('');
|
||||
const botLink = ref('');
|
||||
const pollInterval = ref(null);
|
||||
const connectionToken = ref('');
|
||||
const loading = ref(false);
|
||||
const error = ref('');
|
||||
const showQR = ref(false);
|
||||
const qrCode = ref('');
|
||||
const botLink = ref('');
|
||||
const pollInterval = ref(null);
|
||||
const connectionToken = ref('');
|
||||
|
||||
const startConnection = async () => {
|
||||
try {
|
||||
loading.value = true;
|
||||
const startConnection = async () => {
|
||||
try {
|
||||
loading.value = true;
|
||||
error.value = '';
|
||||
|
||||
const response = await axios.post('/api/auth/telegram/start-connection');
|
||||
|
||||
if (response.data.success) {
|
||||
connectionToken.value = response.data.token;
|
||||
botLink.value = `https://t.me/${response.data.botUsername}?start=${connectionToken.value}`;
|
||||
|
||||
// Генерируем QR-код
|
||||
const qr = await QRCode.toDataURL(botLink.value);
|
||||
qrCode.value = `<img src="${qr}" alt="Telegram QR Code" />`;
|
||||
|
||||
showQR.value = true;
|
||||
startPolling();
|
||||
} else {
|
||||
error.value = response.data.error || 'Не удалось начать процесс подключения';
|
||||
}
|
||||
} catch (err) {
|
||||
error.value = err.response?.data?.error || 'Ошибка при подключении Telegram';
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const checkConnection = async () => {
|
||||
try {
|
||||
const response = await axios.post('/api/auth/telegram/check-connection', {
|
||||
token: connectionToken.value,
|
||||
});
|
||||
|
||||
if (response.data.success && response.data.telegramId) {
|
||||
// Связываем Telegram с текущим пользователем
|
||||
await linkIdentity('telegram', response.data.telegramId);
|
||||
stopPolling();
|
||||
emit('close');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error checking connection:', error);
|
||||
}
|
||||
};
|
||||
|
||||
const startPolling = () => {
|
||||
pollInterval.value = setInterval(checkConnection, 2000);
|
||||
};
|
||||
|
||||
const stopPolling = () => {
|
||||
if (pollInterval.value) {
|
||||
clearInterval(pollInterval.value);
|
||||
pollInterval.value = null;
|
||||
}
|
||||
};
|
||||
|
||||
const resetConnection = () => {
|
||||
stopPolling();
|
||||
showQR.value = false;
|
||||
error.value = '';
|
||||
|
||||
const response = await axios.post('/api/auth/telegram/start-connection');
|
||||
|
||||
if (response.data.success) {
|
||||
connectionToken.value = response.data.token;
|
||||
botLink.value = `https://t.me/${response.data.botUsername}?start=${connectionToken.value}`;
|
||||
|
||||
// Генерируем QR-код
|
||||
const qr = await QRCode.toDataURL(botLink.value);
|
||||
qrCode.value = `<img src="${qr}" alt="Telegram QR Code" />`;
|
||||
|
||||
showQR.value = true;
|
||||
startPolling();
|
||||
} else {
|
||||
error.value = response.data.error || 'Не удалось начать процесс подключения';
|
||||
}
|
||||
} catch (err) {
|
||||
error.value = err.response?.data?.error || 'Ошибка при подключении Telegram';
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
};
|
||||
qrCode.value = '';
|
||||
botLink.value = '';
|
||||
connectionToken.value = '';
|
||||
};
|
||||
|
||||
const checkConnection = async () => {
|
||||
try {
|
||||
const response = await axios.post('/api/auth/telegram/check-connection', {
|
||||
token: connectionToken.value
|
||||
});
|
||||
|
||||
if (response.data.success && response.data.telegramId) {
|
||||
// Связываем Telegram с текущим пользователем
|
||||
await linkIdentity('telegram', response.data.telegramId);
|
||||
stopPolling();
|
||||
emit('close');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error checking connection:', error);
|
||||
}
|
||||
};
|
||||
|
||||
const startPolling = () => {
|
||||
pollInterval.value = setInterval(checkConnection, 2000);
|
||||
};
|
||||
|
||||
const stopPolling = () => {
|
||||
if (pollInterval.value) {
|
||||
clearInterval(pollInterval.value);
|
||||
pollInterval.value = null;
|
||||
}
|
||||
};
|
||||
|
||||
const resetConnection = () => {
|
||||
stopPolling();
|
||||
showQR.value = false;
|
||||
error.value = '';
|
||||
qrCode.value = '';
|
||||
botLink.value = '';
|
||||
connectionToken.value = '';
|
||||
};
|
||||
|
||||
onUnmounted(() => {
|
||||
stopPolling();
|
||||
});
|
||||
onUnmounted(() => {
|
||||
stopPolling();
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.telegram-connect {
|
||||
padding: 20px;
|
||||
max-width: 400px;
|
||||
}
|
||||
|
||||
.intro,
|
||||
.qr-section {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 15px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.connect-button {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 10px 20px;
|
||||
background-color: #0088cc;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
font-size: 16px;
|
||||
transition: background-color 0.2s;
|
||||
}
|
||||
|
||||
.connect-button:hover:not(:disabled) {
|
||||
background-color: #0077b5;
|
||||
}
|
||||
|
||||
.telegram-icon {
|
||||
margin-right: 10px;
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
.qr-container {
|
||||
background: white;
|
||||
padding: 10px;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.qr-container img {
|
||||
max-width: 200px;
|
||||
height: auto;
|
||||
}
|
||||
|
||||
.or-divider {
|
||||
color: #666;
|
||||
margin: 10px 0;
|
||||
}
|
||||
|
||||
.bot-link {
|
||||
color: #0088cc;
|
||||
text-decoration: none;
|
||||
padding: 8px 16px;
|
||||
border: 1px solid #0088cc;
|
||||
border-radius: 4px;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.bot-link:hover {
|
||||
background-color: #0088cc;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.reset-button {
|
||||
padding: 8px 16px;
|
||||
background-color: #e2e8f0;
|
||||
color: #4a5568;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
transition: background-color 0.2s;
|
||||
}
|
||||
|
||||
.reset-button:hover {
|
||||
background-color: #cbd5e0;
|
||||
}
|
||||
|
||||
.error {
|
||||
color: #e53e3e;
|
||||
margin-top: 10px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
button:disabled {
|
||||
opacity: 0.7;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
</style>
|
||||
|
||||
|
||||
@@ -2,11 +2,7 @@
|
||||
<div class="wallet-connection">
|
||||
<div v-if="!isConnected" class="connect-section">
|
||||
<p>Подключите свой кошелек для доступа к расширенным функциям</p>
|
||||
<button
|
||||
@click="connectWallet"
|
||||
:disabled="isLoading"
|
||||
class="wallet-btn"
|
||||
>
|
||||
<button :disabled="isLoading" class="wallet-btn" @click="connectWallet">
|
||||
<span class="wallet-icon">💳</span>
|
||||
{{ isLoading ? 'Подключение...' : 'Подключить кошелек' }}
|
||||
</button>
|
||||
@@ -20,106 +16,48 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, computed } from 'vue';
|
||||
import { useAuth } from '@/composables/useAuth';
|
||||
import { connectWithWallet } from '@/services/wallet';
|
||||
import { ref, computed } from 'vue';
|
||||
import { useAuth } from '@/composables/useAuth';
|
||||
import { connectWithWallet } from '@/services/wallet';
|
||||
|
||||
const emit = defineEmits(['close']);
|
||||
const { linkIdentity } = useAuth();
|
||||
const emit = defineEmits(['close']);
|
||||
const { linkIdentity } = useAuth();
|
||||
|
||||
const isLoading = ref(false);
|
||||
const error = ref('');
|
||||
const address = ref('');
|
||||
const isLoading = ref(false);
|
||||
const error = ref('');
|
||||
const address = ref('');
|
||||
|
||||
const isConnected = computed(() => !!address.value);
|
||||
const isConnected = computed(() => !!address.value);
|
||||
|
||||
const formatAddress = (addr) => {
|
||||
if (!addr) return '';
|
||||
return `${addr.slice(0, 6)}...${addr.slice(-4)}`;
|
||||
};
|
||||
const formatAddress = (addr) => {
|
||||
if (!addr) return '';
|
||||
return `${addr.slice(0, 6)}...${addr.slice(-4)}`;
|
||||
};
|
||||
|
||||
const connectWallet = async () => {
|
||||
if (isLoading.value) return;
|
||||
|
||||
try {
|
||||
isLoading.value = true;
|
||||
error.value = '';
|
||||
|
||||
// Подключаем кошелек
|
||||
const result = await connectWithWallet();
|
||||
|
||||
if (result.success) {
|
||||
address.value = result.address;
|
||||
|
||||
// Связываем кошелек с текущим пользователем
|
||||
await linkIdentity('wallet', result.address);
|
||||
emit('close');
|
||||
} else {
|
||||
error.value = result.error || 'Не удалось подключить кошелек';
|
||||
const connectWallet = async () => {
|
||||
if (isLoading.value) return;
|
||||
|
||||
try {
|
||||
isLoading.value = true;
|
||||
error.value = '';
|
||||
|
||||
// Подключаем кошелек
|
||||
const result = await connectWithWallet();
|
||||
|
||||
if (result.success) {
|
||||
address.value = result.address;
|
||||
|
||||
// Связываем кошелек с текущим пользователем
|
||||
await linkIdentity('wallet', result.address);
|
||||
emit('close');
|
||||
} else {
|
||||
error.value = result.error || 'Не удалось подключить кошелек';
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Error connecting wallet:', err);
|
||||
error.value = err.message || 'Произошла ошибка при подключении кошелька';
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Error connecting wallet:', err);
|
||||
error.value = err.message || 'Произошла ошибка при подключении кошелька';
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
}
|
||||
};
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.wallet-connection {
|
||||
padding: 20px;
|
||||
max-width: 400px;
|
||||
}
|
||||
|
||||
.connect-section,
|
||||
.status-section {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 15px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.wallet-btn {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 10px 20px;
|
||||
background-color: #4a5568;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
font-size: 16px;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.wallet-btn:hover:not(:disabled) {
|
||||
background-color: #2d3748;
|
||||
}
|
||||
|
||||
.wallet-icon {
|
||||
margin-right: 10px;
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
.address {
|
||||
font-family: monospace;
|
||||
background-color: #f7fafc;
|
||||
padding: 8px 12px;
|
||||
border-radius: 4px;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.error {
|
||||
color: #e53e3e;
|
||||
margin-top: 10px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
button:disabled {
|
||||
opacity: 0.7;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
</style>
|
||||
@@ -2,8 +2,4 @@ import TelegramConnect from './TelegramConnect.vue';
|
||||
import WalletConnection from './WalletConnection.vue';
|
||||
import EmailConnect from './EmailConnect.vue';
|
||||
|
||||
export {
|
||||
TelegramConnect,
|
||||
WalletConnection,
|
||||
EmailConnect
|
||||
};
|
||||
export { TelegramConnect, WalletConnection, EmailConnect };
|
||||
|
||||
Reference in New Issue
Block a user