Files
vue-pult/server/api/auth-server.js
sasha 3e90269b0b Initial commit: Vue.js тир управления система
- Клиентская часть Vue 3 + Vite
- Серверная часть Node.js + WebSocket
- Система авторизации и смен
- Управление игровыми портами
- Поддержка тем (светлая/темная)
- Адаптивный дизайн

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-19 12:24:22 +03:00

101 lines
4.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"use strict";
exports.go = async (req, res, postData, urlParsed) => {
try {
console.log('[api/auth-server] Авторизация через внешний сервер:', postData);
// Проверяем соединение с внешним сервером
if (!global.conn_to_server) {
console.error('[api/auth-server] Нет соединения с внешним сервером');
return res.end(JSON.stringify({
success: false,
error: "Нет соединения с сервером"
}));
}
if (!postData || !postData.phone || !postData.password) {
return res.end(JSON.stringify({
success: false,
error: "Не указан номер телефона или пароль"
}));
}
// Нормализуем номер телефона
const normalizedPhone = postData.phone.replace(/\D/g, '');
console.log('[api/auth-server] Попытка авторизации через сервер для:', normalizedPhone);
// ПРОБУЕМ АВТОРИЗАЦИЮ НА ВНЕШНЕМ СЕРВЕРЕ БЕЗ serialcpu
// Может быть есть отдельный метод для авторизации пользователей
const authResponse = await global.send_to_server({
do: "user/auth", // Попробуем другой метод
tel: normalizedPhone,
pass: postData.password
});
console.log('[api/auth-server] Ответ от сервера (user/auth):', JSON.stringify(authResponse, null, 2));
if (authResponse.err) {
// Если user/auth не работает, попробуем старый метод avt
console.log('[api/auth-server] Пробуем метод avt...');
const authResponse2 = await global.send_to_server({
do: "avt",
tel: normalizedPhone,
pass: postData.password
// НЕ отправляем serialcpu - может сработать для пользователей
});
console.log('[api/auth-server] Ответ от сервера (avt без serialcpu):', JSON.stringify(authResponse2, null, 2));
if (authResponse2.err) {
return res.end(JSON.stringify({
success: false,
error: "Ошибка авторизации на сервере: " + authResponse2.err
}));
}
// Если авторизация успешна
if (authResponse2.user) {
return res.end(JSON.stringify({
success: true,
user: {
id: authResponse2.user._id || normalizedPhone,
name: authResponse2.user.fio || authResponse2.user.name || 'Пользователь',
phone: normalizedPhone,
role: authResponse2.user.taccess || 'operator',
isAuthenticated: true,
serverAuth: true,
serverConnected: true
}
}));
}
} else if (authResponse.user) {
// user/auth сработал
return res.end(JSON.stringify({
success: true,
user: {
id: authResponse.user._id || normalizedPhone,
name: authResponse.user.fio || authResponse.user.name || 'Пользователь',
phone: normalizedPhone,
role: authResponse.user.taccess || 'operator',
isAuthenticated: true,
serverAuth: true,
serverConnected: true
}
}));
}
return res.end(JSON.stringify({
success: false,
error: "Неверный логин или пароль"
}));
} catch (error) {
console.error('[api/auth-server] Критическая ошибка:', error);
res.end(JSON.stringify({
success: false,
error: "Внутренняя ошибка сервера"
}));
}
};