ваше сообщение коммита

This commit is contained in:
2025-09-24 13:05:20 +03:00
parent de0f8aecf2
commit 76cde4b53d
45 changed files with 2167 additions and 2854 deletions

View File

@@ -24,6 +24,7 @@ const email = ref(null);
const processedGuestIds = ref([]);
const identities = ref([]);
const tokenBalances = ref([]);
const userAccessLevel = ref({ level: 'user', tokenCount: 0, hasAccess: false });
// Функция для обновления списка идентификаторов
const updateIdentities = async () => {
@@ -95,6 +96,20 @@ const checkTokenBalances = async (address) => {
}
};
const checkUserAccessLevel = async (address) => {
try {
const response = await axios.get(`/auth/access-level/${address}`);
if (response.data.success) {
userAccessLevel.value = response.data.data;
return response.data.data;
}
return null;
} catch (error) {
console.error('Error checking user access level:', error);
return null;
}
};
const updateAuth = async ({
authenticated,
authType: newAuthType,
@@ -140,9 +155,10 @@ const updateAuth = async ({
})
);
// Если аутентификация через кошелек, проверяем баланс токенов
// Если аутентификация через кошелек, проверяем баланс токенов и уровень доступа
if (authenticated && newAuthType === 'wallet' && newAddress) {
await checkTokenBalances(newAddress);
await checkUserAccessLevel(newAddress);
}
// Обновляем идентификаторы при любом изменении аутентификации
@@ -465,6 +481,7 @@ const authApi = {
identities,
processedGuestIds,
tokenBalances,
userAccessLevel,
updateAuth,
checkAuth,
disconnect,
@@ -475,6 +492,7 @@ const authApi = {
linkIdentity,
deleteIdentity,
checkTokenBalances,
checkUserAccessLevel,
};
// === PROVIDE/INJECT HELPERS ===

View File

@@ -0,0 +1,105 @@
/**
* Copyright (c) 2024-2025 Тарабанов Александр Викторович
* All rights reserved.
*
* This software is proprietary and confidential.
* Unauthorized copying, modification, or distribution is prohibited.
*
* For licensing inquiries: info@hb3-accelerator.com
* Website: https://hb3-accelerator.com
* GitHub: https://github.com/HB3-ACCELERATOR
*/
import { computed } from 'vue';
import { useAuthContext } from './useAuth';
/**
* Composable для работы с правами доступа
* @returns {Object} - Объект с функциями для проверки прав доступа
*/
export function usePermissions() {
const { userAccessLevel, isAdmin } = useAuthContext();
/**
* Проверяет, может ли пользователь только читать данные
*/
const canRead = computed(() => {
return userAccessLevel.value && userAccessLevel.value.hasAccess;
});
/**
* Проверяет, может ли пользователь редактировать данные
*/
const canEdit = computed(() => {
return userAccessLevel.value && userAccessLevel.value.level === 'editor';
});
/**
* Проверяет, может ли пользователь удалять данные
*/
const canDelete = computed(() => {
return userAccessLevel.value && userAccessLevel.value.level === 'editor';
});
/**
* Проверяет, может ли пользователь управлять настройками системы
*/
const canManageSettings = computed(() => {
return userAccessLevel.value && userAccessLevel.value.level === 'editor';
});
/**
* Получает текущий уровень доступа
*/
const currentLevel = computed(() => {
return userAccessLevel.value ? userAccessLevel.value.level : 'user';
});
/**
* Получает количество токенов пользователя
*/
const tokenCount = computed(() => {
return userAccessLevel.value ? userAccessLevel.value.tokenCount : 0;
});
/**
* Получает описание текущего уровня доступа
*/
const getLevelDescription = (level) => {
switch (level) {
case 'readonly':
return 'Только чтение';
case 'editor':
return 'Редактор';
case 'user':
default:
return 'Пользователь';
}
};
/**
* Получает CSS класс для уровня доступа
*/
const getLevelClass = (level) => {
switch (level) {
case 'readonly':
return 'access-readonly';
case 'editor':
return 'access-editor';
case 'user':
default:
return 'access-user';
}
};
return {
canRead,
canEdit,
canDelete,
canManageSettings,
currentLevel,
tokenCount,
getLevelDescription,
getLevelClass
};
}