ваше сообщение коммита
This commit is contained in:
@@ -43,18 +43,60 @@
|
||||
</router-link>
|
||||
</div>
|
||||
|
||||
<!-- Блок информации о пользователе -->
|
||||
<div v-if="isAuthenticated" class="user-info-section sidebar-section">
|
||||
<h3>Ваши идентификаторы:</h3>
|
||||
<div class="user-info-item">
|
||||
<span class="user-info-label">Кошелек:</span>
|
||||
<span v-if="hasIdentityType('wallet')" class="user-info-value">
|
||||
{{ truncateAddress(getIdentityValue('wallet')) }}
|
||||
</span>
|
||||
<span v-else class="user-info-value">Не подключен</span>
|
||||
<!-- Блок информации о пользователе или формы подключения -->
|
||||
<template v-if="isAuthenticated">
|
||||
<div v-if="emailAuth.showForm || emailAuth.showVerification" class="auth-modal-panel">
|
||||
<EmailConnect @success="$emit('cancel-email-auth')">
|
||||
<template #actions>
|
||||
<button class="close-btn" @click="$emit('cancel-email-auth')">Отмена</button>
|
||||
</template>
|
||||
</EmailConnect>
|
||||
</div>
|
||||
<!-- Можно добавить другие идентификаторы по аналогии -->
|
||||
</div>
|
||||
<div v-else-if="telegramAuth.showVerification" class="auth-modal-panel">
|
||||
<TelegramConnect
|
||||
:bot-link="telegramAuth.botLink"
|
||||
:verification-code="telegramAuth.verificationCode"
|
||||
:error="telegramAuth.error"
|
||||
@cancel="$emit('cancel-telegram-auth')"
|
||||
/>
|
||||
</div>
|
||||
<div v-else class="user-info-section sidebar-section">
|
||||
<h3>Ваши идентификаторы:</h3>
|
||||
<div class="user-info-item">
|
||||
<span class="user-info-label">Кошелек:</span>
|
||||
<span v-if="hasIdentityType('wallet')" class="user-info-value">
|
||||
{{ truncateAddress(getIdentityValue('wallet')) }}
|
||||
<button class="delete-identity-btn" @click="handleDeleteIdentity('wallet', getIdentityValue('wallet'))" title="Удалить">✕</button>
|
||||
</span>
|
||||
<span v-else class="user-info-value">
|
||||
Не подключен
|
||||
<button class="connect-btn" @click="handleWalletAuth">Подключить</button>
|
||||
</span>
|
||||
</div>
|
||||
<div class="user-info-item">
|
||||
<span class="user-info-label">Telegram:</span>
|
||||
<span v-if="hasIdentityType('telegram')" class="user-info-value">
|
||||
{{ getIdentityValue('telegram') }}
|
||||
<button class="delete-identity-btn" @click="handleDeleteIdentity('telegram', getIdentityValue('telegram'))" title="Удалить">✕</button>
|
||||
</span>
|
||||
<span v-else class="user-info-value">
|
||||
Не подключен
|
||||
<button class="connect-btn" @click="$emit('telegram-auth')">Подключить</button>
|
||||
</span>
|
||||
</div>
|
||||
<div class="user-info-item">
|
||||
<span class="user-info-label">Email:</span>
|
||||
<span v-if="hasIdentityType('email')" class="user-info-value">
|
||||
{{ getIdentityValue('email') }}
|
||||
<button class="delete-identity-btn" @click="handleDeleteIdentity('email', getIdentityValue('email'))" title="Удалить">✕</button>
|
||||
</span>
|
||||
<span v-else class="user-info-value">
|
||||
Не подключен
|
||||
<button class="connect-btn" @click="$emit('email-auth')">Подключить</button>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- Блок баланса токенов -->
|
||||
<div v-if="isAuthenticated" class="token-balances-section sidebar-section">
|
||||
@@ -85,6 +127,9 @@
|
||||
import { defineProps, defineEmits, ref, onMounted, onBeforeUnmount, watch } from 'vue';
|
||||
import { useRouter } from 'vue-router';
|
||||
import eventBus from '../utils/eventBus';
|
||||
import EmailConnect from './identity/EmailConnect.vue';
|
||||
import TelegramConnect from './identity/TelegramConnect.vue';
|
||||
import { useAuth } from '@/composables/useAuth';
|
||||
|
||||
const router = useRouter();
|
||||
const props = defineProps({
|
||||
@@ -97,7 +142,9 @@ const props = defineProps({
|
||||
isLoadingTokens: Boolean
|
||||
});
|
||||
|
||||
const emit = defineEmits(['update:modelValue', 'wallet-auth', 'disconnect-wallet']);
|
||||
const emit = defineEmits(['update:modelValue', 'wallet-auth', 'disconnect-wallet', 'telegram-auth', 'email-auth']);
|
||||
|
||||
const { deleteIdentity } = useAuth();
|
||||
|
||||
// Обработчики событий
|
||||
const handleWalletAuth = () => {
|
||||
@@ -149,6 +196,12 @@ const getIdentityValue = (type) => {
|
||||
return identity ? identity.provider_id : null;
|
||||
};
|
||||
|
||||
const handleDeleteIdentity = async (provider, providerId) => {
|
||||
if (confirm('Удалить идентификатор?')) {
|
||||
await deleteIdentity(provider, providerId);
|
||||
}
|
||||
};
|
||||
|
||||
// Добавляем watch для отслеживания props
|
||||
watch(() => props.tokenBalances, (newVal, oldVal) => {
|
||||
console.log('[Sidebar] tokenBalances prop changed:', JSON.stringify(newVal));
|
||||
@@ -440,4 +493,47 @@ h3 {
|
||||
text-align: right;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
|
||||
.connect-btn {
|
||||
margin-left: 10px;
|
||||
background: var(--color-primary);
|
||||
color: #fff;
|
||||
border: none;
|
||||
border-radius: 6px;
|
||||
padding: 0.2rem 0.8rem;
|
||||
cursor: pointer;
|
||||
font-size: 0.95rem;
|
||||
transition: background 0.2s;
|
||||
}
|
||||
.connect-btn:hover {
|
||||
background: var(--color-primary-dark);
|
||||
}
|
||||
|
||||
.auth-modal-panel {
|
||||
background: #fff;
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 2px 16px rgba(0,0,0,0.15);
|
||||
padding: 2rem 2.5rem;
|
||||
max-width: 400px;
|
||||
width: 100%;
|
||||
margin: 2rem auto;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.delete-identity-btn {
|
||||
margin-left: 8px;
|
||||
background: none;
|
||||
border: none;
|
||||
color: #d32f2f;
|
||||
font-size: 1.1rem;
|
||||
cursor: pointer;
|
||||
padding: 0 4px;
|
||||
border-radius: 3px;
|
||||
transition: background 0.15s;
|
||||
}
|
||||
.delete-identity-btn:hover {
|
||||
background: #ffeaea;
|
||||
}
|
||||
</style>
|
||||
@@ -1,90 +1,236 @@
|
||||
<template>
|
||||
<div class="email-connection">
|
||||
<div v-if="!showVerification" class="email-form">
|
||||
<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 :disabled="isLoading || !code" class="verify-btn" @click="verifyCode">
|
||||
{{ isLoading ? 'Проверка...' : 'Подтвердить' }}
|
||||
</button>
|
||||
<button class="reset-btn" @click="resetForm">Изменить email</button>
|
||||
</div>
|
||||
<div v-if="error" class="error">{{ error }}</div>
|
||||
<form @submit.prevent="showVerification ? verifyCode() : requestCode()" class="email-form-panel">
|
||||
<div class="form-header">
|
||||
<div>
|
||||
<div class="form-title">Email</div>
|
||||
<div class="form-step">{{ showVerification ? 'Шаг 2 из 2' : 'Шаг 1 из 2' }}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="!showVerification" class="email-form">
|
||||
<label for="email-input" class="form-label">Email</label>
|
||||
<input id="email-input" v-model="email" type="email" placeholder="Введите email" class="email-input" :disabled="isLoading" autocomplete="email" />
|
||||
<div class="form-hint">На этот адрес придёт код подтверждения</div>
|
||||
<button type="submit" :disabled="isLoading || !isValidEmail" class="email-btn main-btn">
|
||||
{{ isLoading ? 'Отправка...' : 'Получить код' }}
|
||||
</button>
|
||||
</div>
|
||||
<div v-else class="verification-form">
|
||||
<p class="verification-info success-msg">Код отправлен на <b>{{ email }}</b></p>
|
||||
<label for="code-input" class="form-label">Код</label>
|
||||
<input id="code-input" v-model="code" type="text" placeholder="Введите код из письма" class="code-input" :disabled="isLoading" autocomplete="one-time-code" />
|
||||
<div class="form-hint">Проверьте почту и введите код из письма</div>
|
||||
<button type="submit" :disabled="isLoading || !code" class="verify-btn main-btn">
|
||||
{{ isLoading ? 'Проверка...' : 'Подтвердить' }}
|
||||
</button>
|
||||
<button type="button" class="reset-btn link-btn" @click="resetForm" :disabled="isLoading">Изменить email</button>
|
||||
</div>
|
||||
<div v-if="error" class="error-msg">{{ error }}</div>
|
||||
<div class="actions">
|
||||
<slot name="actions">
|
||||
<button type="button" class="cancel-btn" @click="$emit('close')" :disabled="isLoading">Отмена</button>
|
||||
</slot>
|
||||
</div>
|
||||
</form>
|
||||
</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', 'success']);
|
||||
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 || 'Ошибка отправки кода';
|
||||
}
|
||||
} 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 || 'Неверный код';
|
||||
}
|
||||
} catch (err) {
|
||||
error.value = err.response?.data?.error || 'Ошибка проверки кода';
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const resetForm = () => {
|
||||
email.value = '';
|
||||
code.value = '';
|
||||
const requestCode = async () => {
|
||||
try {
|
||||
isLoading.value = true;
|
||||
error.value = '';
|
||||
showVerification.value = false;
|
||||
};
|
||||
const response = await axios.post('/api/auth/email/request', {
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
const verifyCode = async () => {
|
||||
try {
|
||||
isLoading.value = true;
|
||||
error.value = '';
|
||||
const response = await axios.post('/api/auth/email/verify-code', {
|
||||
email: email.value,
|
||||
code: code.value,
|
||||
});
|
||||
if (response.data.success) {
|
||||
emit('success');
|
||||
} else {
|
||||
error.value = response.data.error || 'Неверный код';
|
||||
}
|
||||
} catch (err) {
|
||||
error.value = err.response?.data?.error || 'Ошибка проверки кода';
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const resetForm = () => {
|
||||
email.value = '';
|
||||
code.value = '';
|
||||
error.value = '';
|
||||
showVerification.value = false;
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.email-connection {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
}
|
||||
.email-form-panel {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
gap: 1.2rem;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
background: none;
|
||||
border-radius: 0;
|
||||
box-shadow: none;
|
||||
}
|
||||
.form-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 1rem;
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
.form-title {
|
||||
font-size: 1.2rem;
|
||||
font-weight: 600;
|
||||
color: var(--color-primary, #2e7d32);
|
||||
}
|
||||
.form-step {
|
||||
font-size: 0.98rem;
|
||||
color: var(--color-grey, #888);
|
||||
}
|
||||
.form-label {
|
||||
font-size: 1rem;
|
||||
color: var(--color-primary, #2e7d32);
|
||||
margin-bottom: 0.3rem;
|
||||
font-weight: 500;
|
||||
}
|
||||
.form-hint {
|
||||
font-size: 0.95rem;
|
||||
color: var(--color-grey, #888);
|
||||
margin-bottom: 0.5rem;
|
||||
margin-top: -0.3rem;
|
||||
}
|
||||
.email-input, .code-input {
|
||||
border: 1px solid var(--color-grey, #ccc);
|
||||
border-radius: 4px;
|
||||
padding: 0 1rem;
|
||||
font-size: 1rem;
|
||||
margin-bottom: 0.7rem;
|
||||
outline: none;
|
||||
width: 100%;
|
||||
height: 44px;
|
||||
box-shadow: none;
|
||||
transition: none;
|
||||
}
|
||||
.email-input:focus, .code-input:focus {
|
||||
border-color: var(--color-primary, #2e7d32);
|
||||
}
|
||||
.email-btn, .verify-btn, .main-btn, .cancel-btn {
|
||||
width: 100%;
|
||||
height: 44px;
|
||||
background: var(--color-primary, #2e7d32);
|
||||
color: #fff;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
font-size: 1.05rem;
|
||||
cursor: pointer;
|
||||
margin-bottom: 0.5rem;
|
||||
font-weight: 500;
|
||||
box-shadow: none;
|
||||
transition: none;
|
||||
}
|
||||
.email-btn:disabled, .verify-btn:disabled, .main-btn:disabled {
|
||||
background: var(--color-grey-light, #e0e0e0);
|
||||
color: #aaa;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
.reset-btn.link-btn {
|
||||
background: none;
|
||||
border: none;
|
||||
color: var(--color-primary, #2e7d32);
|
||||
text-decoration: underline;
|
||||
cursor: pointer;
|
||||
font-size: 0.95rem;
|
||||
margin-top: 0.2rem;
|
||||
margin-bottom: 0.5rem;
|
||||
width: 100%;
|
||||
height: 44px;
|
||||
text-align: left;
|
||||
padding-left: 0;
|
||||
}
|
||||
.reset-btn.link-btn:disabled {
|
||||
color: #aaa;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
.error-msg {
|
||||
color: #d32f2f;
|
||||
font-size: 1.05rem;
|
||||
margin-top: 0.2rem;
|
||||
margin-bottom: 0.2rem;
|
||||
text-align: left;
|
||||
font-weight: 500;
|
||||
}
|
||||
.success-msg {
|
||||
color: var(--color-primary, #2e7d32);
|
||||
font-size: 1.05rem;
|
||||
font-weight: 500;
|
||||
}
|
||||
.verification-info {
|
||||
margin-bottom: 0.7rem;
|
||||
}
|
||||
.actions {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
margin-top: 0.5rem;
|
||||
}
|
||||
.cancel-btn {
|
||||
background: var(--color-grey-light, #e0e0e0);
|
||||
color: var(--color-dark, #222);
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
font-size: 1rem;
|
||||
font-weight: 400;
|
||||
margin-bottom: 0;
|
||||
margin-top: 0.2rem;
|
||||
box-shadow: none;
|
||||
transition: none;
|
||||
}
|
||||
.cancel-btn:hover {
|
||||
background: var(--color-grey, #bdbdbd);
|
||||
}
|
||||
</style>
|
||||
|
||||
123
frontend/src/components/identity/TelegramConnect.vue
Normal file
123
frontend/src/components/identity/TelegramConnect.vue
Normal file
@@ -0,0 +1,123 @@
|
||||
<template>
|
||||
<form class="tg-form-panel" @submit.prevent>
|
||||
<div class="tg-header">
|
||||
<div>
|
||||
<div class="tg-title">Telegram</div>
|
||||
<div class="tg-step">Шаг 1 из 2</div>
|
||||
</div>
|
||||
</div>
|
||||
<ol class="tg-steps">
|
||||
<li>
|
||||
Откройте Telegram-бота:<br>
|
||||
<a :href="botLink" target="_blank" class="tg-link">{{ botLink }}</a>
|
||||
<div class="tg-hint">Ссылка откроется в новом окне</div>
|
||||
</li>
|
||||
<li>
|
||||
Введите код:
|
||||
<span class="tg-code">{{ verificationCode }}</span>
|
||||
<span class="tg-hint">Скопируйте и отправьте этот код боту</span>
|
||||
</li>
|
||||
</ol>
|
||||
<p v-if="error" class="tg-error">{{ error }}</p>
|
||||
<button type="button" class="tg-cancel-btn" @click="$emit('cancel')">Отмена</button>
|
||||
</form>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
const props = defineProps({
|
||||
botLink: String,
|
||||
verificationCode: String,
|
||||
error: String
|
||||
});
|
||||
const emit = defineEmits(['cancel']);
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.tg-form-panel {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
gap: 1.2rem;
|
||||
margin: 0;
|
||||
background: none;
|
||||
border-radius: 0;
|
||||
box-shadow: none;
|
||||
padding: 0;
|
||||
}
|
||||
.tg-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 1rem;
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
.tg-title {
|
||||
font-size: 1.2rem;
|
||||
font-weight: 600;
|
||||
color: var(--color-primary, #2e7d32);
|
||||
}
|
||||
.tg-step {
|
||||
font-size: 0.98rem;
|
||||
color: var(--color-grey, #888);
|
||||
}
|
||||
.tg-steps {
|
||||
padding-left: 1.2rem;
|
||||
margin-bottom: 0.7rem;
|
||||
color: var(--color-dark, #222);
|
||||
font-size: 1rem;
|
||||
word-break: break-all;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1.2rem;
|
||||
}
|
||||
.tg-link {
|
||||
color: var(--color-primary, #2e7d32);
|
||||
word-break: break-all;
|
||||
text-decoration: underline;
|
||||
font-size: 1.05rem;
|
||||
font-weight: 500;
|
||||
}
|
||||
.tg-hint {
|
||||
font-size: 0.95rem;
|
||||
color: var(--color-grey, #888);
|
||||
margin-top: 0.2rem;
|
||||
}
|
||||
.tg-code {
|
||||
display: inline-block;
|
||||
background: var(--color-grey-light, #e0e0e0);
|
||||
color: #222;
|
||||
border-radius: 4px;
|
||||
padding: 0.2rem 0.7rem;
|
||||
font-weight: bold;
|
||||
font-size: 1.1rem;
|
||||
letter-spacing: 1px;
|
||||
margin-left: 0.5rem;
|
||||
height: 44px;
|
||||
line-height: 44px;
|
||||
}
|
||||
.tg-error {
|
||||
color: #d32f2f;
|
||||
font-size: 1.05rem;
|
||||
margin-top: 0.2rem;
|
||||
margin-bottom: 0.2rem;
|
||||
text-align: left;
|
||||
font-weight: 500;
|
||||
}
|
||||
.tg-cancel-btn {
|
||||
width: 100%;
|
||||
height: 44px;
|
||||
background: var(--color-grey-light, #e0e0e0);
|
||||
color: var(--color-dark, #222);
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
font-size: 1rem;
|
||||
font-weight: 400;
|
||||
margin-bottom: 0;
|
||||
margin-top: 0.2rem;
|
||||
box-shadow: none;
|
||||
transition: none;
|
||||
}
|
||||
.tg-cancel-btn:hover {
|
||||
background: var(--color-grey, #bdbdbd);
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user