stigmergy 1.2.0 → 1.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +18 -18
- package/README.md +28 -223
- package/STIGMERGY.md +61 -61
- package/docs/PROJECT_CONSTITUTION.md +433 -433
- package/docs/PROJECT_STRUCTURE_CURRENT.md +80 -80
- package/examples/calculator-example.js +72 -72
- package/examples/cline_usage_examples.md +364 -364
- package/examples/encryption-example.js +67 -67
- package/examples/json-parser-example.js +120 -120
- package/examples/json-validation-example.js +64 -64
- package/examples/rest-client-example.js +52 -52
- package/examples/rest_client_example.js +54 -54
- package/package.json +36 -15
- package/scripts/build.js +74 -74
- package/scripts/post-deployment-config.js +296 -296
- package/scripts/preinstall-check.js +173 -173
- package/scripts/publish.js +58 -268
- package/scripts/run-layered-tests.js +247 -0
- package/scripts/safe-install.js +139 -139
- package/scripts/simple-publish.js +57 -59
- package/src/adapters/claude/install_claude_integration.js +292 -0
- package/src/adapters/codebuddy/install_codebuddy_integration.js +349 -0
- package/src/adapters/codex/install_codex_integration.js +395 -0
- package/src/adapters/copilot/install_copilot_integration.js +716 -0
- package/src/adapters/gemini/install_gemini_integration.js +304 -0
- package/src/adapters/iflow/install_iflow_integration.js +304 -0
- package/src/adapters/qoder/install_qoder_integration.js +1090 -0
- package/src/adapters/qwen/install_qwen_integration.js +285 -0
- package/src/auth.js +173 -173
- package/src/auth_command.js +208 -208
- package/src/calculator.js +313 -313
- package/src/cli/router.js +417 -38
- package/src/core/cache_cleaner.js +767 -744
- package/src/core/cli_help_analyzer.js +680 -674
- package/src/core/cli_parameter_handler.js +132 -127
- package/src/core/cli_tools.js +89 -89
- package/src/core/coordination/index.js +16 -16
- package/src/core/coordination/nodejs/AdapterManager.js +102 -89
- package/src/core/coordination/nodejs/CLCommunication.js +132 -124
- package/src/core/coordination/nodejs/CLIIntegrationManager.js +272 -236
- package/src/core/coordination/nodejs/HealthChecker.js +76 -77
- package/src/core/coordination/nodejs/HookDeploymentManager.js +263 -190
- package/src/core/coordination/nodejs/StatisticsCollector.js +71 -71
- package/src/core/coordination/nodejs/index.js +90 -72
- package/src/core/coordination/nodejs/utils/Logger.js +29 -29
- package/src/core/enhanced_installer.js +479 -456
- package/src/core/enhanced_uninstaller.js +638 -618
- package/src/core/error_handler.js +406 -406
- package/src/core/installer.js +815 -294
- package/src/core/memory_manager.js +83 -83
- package/src/core/rest_client.js +160 -160
- package/src/core/smart_router.js +249 -146
- package/src/core/upgrade_manager.js +76 -59
- package/src/data_encryption.js +143 -143
- package/src/data_structures.js +440 -440
- package/src/deploy.js +55 -55
- package/src/index.js +30 -30
- package/src/test/cli-availability-checker.js +194 -0
- package/src/test/test-environment.js +289 -0
- package/src/utils/helpers.js +35 -35
- package/src/utils.js +921 -915
- package/src/weatherProcessor.js +228 -228
- package/test/cache-cleaner-implemented.test.js +0 -328
- package/test/cache-cleaner.test.js +0 -390
- package/test/calculator.test.js +0 -215
- package/test/collision-test.js +0 -26
- package/test/comprehensive-enhanced-features.test.js +0 -252
- package/test/comprehensive-execution-test.js +0 -428
- package/test/conflict-prevention-test.js +0 -95
- package/test/cross-cli-detection-test.js +0 -33
- package/test/csv-processing-test.js +0 -36
- package/test/deploy-hooks-test.js +0 -250
- package/test/e2e/claude-cli-test.js +0 -128
- package/test/e2e/collaboration-test.js +0 -75
- package/test/e2e/comprehensive-test.js +0 -431
- package/test/e2e/error-handling-test.js +0 -90
- package/test/e2e/individual-tool-test.js +0 -143
- package/test/e2e/other-cli-test.js +0 -130
- package/test/e2e/qoder-cli-test.js +0 -128
- package/test/e2e/run-e2e-tests.js +0 -73
- package/test/e2e/test-data.js +0 -88
- package/test/e2e/test-utils.js +0 -222
- package/test/encryption-simple-test.js +0 -110
- package/test/encryption.test.js +0 -129
- package/test/enhanced-main-alignment.test.js +0 -298
- package/test/enhanced-uninstaller-implemented.test.js +0 -271
- package/test/enhanced-uninstaller.test.js +0 -284
- package/test/error-handling-test.js +0 -341
- package/test/fibonacci.test.js +0 -178
- package/test/final-deploy-test.js +0 -221
- package/test/final-install-test.js +0 -226
- package/test/hash-table-demo.js +0 -33
- package/test/hash-table-test.js +0 -26
- package/test/hash_table_test.js +0 -114
- package/test/hook-system-integration-test.js +0 -307
- package/test/iflow-integration-test.js +0 -292
- package/test/improved-install-test.js +0 -362
- package/test/install-command-test.js +0 -370
- package/test/json-parser-test.js +0 -161
- package/test/json-validation-test.js +0 -164
- package/test/natural-language-skills-test.js +0 -320
- package/test/nl-integration-test.js +0 -179
- package/test/parameter-parsing-test.js +0 -143
- package/test/plugin-deployment-test.js +0 -316
- package/test/postinstall-test.js +0 -269
- package/test/python-plugins-test.js +0 -259
- package/test/real-test.js +0 -435
- package/test/remaining-adapters-test.js +0 -256
- package/test/rest-client-test.js +0 -56
- package/test/rest_client.test.js +0 -85
- package/test/safe-installation-cleaner.test.js +0 -343
- package/test/simple-iflow-hook-test.js +0 -137
- package/test/stigmergy-upgrade-test.js +0 -243
- package/test/system-compatibility-test.js +0 -467
- package/test/tdd-deploy-fix-test.js +0 -324
- package/test/tdd-fixes-test.js +0 -211
- package/test/third-party-skills-test.js +0 -321
- package/test/tool-selection-integration-test.js +0 -158
- package/test/unit/calculator-full.test.js +0 -191
- package/test/unit/calculator-simple.test.js +0 -96
- package/test/unit/calculator.test.js +0 -97
- package/test/unit/cli-scanner.test.js +0 -291
- package/test/unit/cli_parameter_handler.test.js +0 -116
- package/test/unit/cross-cli-executor.test.js +0 -399
- package/test/weather-processor.test.js +0 -104
package/src/auth_command.js
CHANGED
|
@@ -1,208 +1,208 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Authentication command handler for the Stigmergy CLI.
|
|
3
|
-
* Provides CLI commands for user registration, login, and session management.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
const fs = require('fs');
|
|
7
|
-
const path = require('path');
|
|
8
|
-
const { UserAuthenticator, authenticateAndGetToken } = require('./auth');
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Get the path to the authentication data file.
|
|
12
|
-
* @returns {string} Path to the auth data file
|
|
13
|
-
*/
|
|
14
|
-
function getAuthDataPath() {
|
|
15
|
-
const homeDir = process.env.HOME || process.env.USERPROFILE;
|
|
16
|
-
const configDir = path.join(homeDir, '.stigmergy');
|
|
17
|
-
|
|
18
|
-
// Create config directory if it doesn't exist
|
|
19
|
-
if (!fs.existsSync(configDir)) {
|
|
20
|
-
fs.mkdirSync(configDir, { recursive: true });
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return path.join(configDir, 'auth.json');
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Load authentication data from file.
|
|
28
|
-
* @param {UserAuthenticator} authenticator - The authenticator instance
|
|
29
|
-
*/
|
|
30
|
-
function loadAuthData(authenticator) {
|
|
31
|
-
try {
|
|
32
|
-
const authFile = getAuthDataPath();
|
|
33
|
-
if (fs.existsSync(authFile)) {
|
|
34
|
-
const data = JSON.parse(fs.readFileSync(authFile, 'utf8'));
|
|
35
|
-
|
|
36
|
-
// Load users
|
|
37
|
-
if (data.users) {
|
|
38
|
-
for (const [username, userData] of Object.entries(data.users)) {
|
|
39
|
-
authenticator._users.set(username, userData);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// Load sessions
|
|
44
|
-
if (data.sessions) {
|
|
45
|
-
for (const [token, sessionData] of Object.entries(data.sessions)) {
|
|
46
|
-
authenticator._sessions.set(token, sessionData);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
} catch (error) {
|
|
51
|
-
console.warn('[WARN] Could not load authentication data:', error.message);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Save authentication data to file.
|
|
57
|
-
* @param {UserAuthenticator} authenticator - The authenticator instance
|
|
58
|
-
*/
|
|
59
|
-
function saveAuthData(authenticator) {
|
|
60
|
-
try {
|
|
61
|
-
const authFile = getAuthDataPath();
|
|
62
|
-
|
|
63
|
-
// Convert Maps to objects for JSON serialization
|
|
64
|
-
const users = {};
|
|
65
|
-
for (const [username, userData] of authenticator._users.entries()) {
|
|
66
|
-
users[username] = userData;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const sessions = {};
|
|
70
|
-
for (const [token, sessionData] of authenticator._sessions.entries()) {
|
|
71
|
-
sessions[token] = sessionData;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const data = {
|
|
75
|
-
users,
|
|
76
|
-
sessions,
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
fs.writeFileSync(authFile, JSON.stringify(data, null, 2));
|
|
80
|
-
} catch (error) {
|
|
81
|
-
console.warn('[WARN] Could not save authentication data:', error.message);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Handle user registration.
|
|
87
|
-
* @param {string} username - The username to register
|
|
88
|
-
* @param {string} password - The password for the user
|
|
89
|
-
*/
|
|
90
|
-
function handleRegister(username, password) {
|
|
91
|
-
const authenticator = new UserAuthenticator();
|
|
92
|
-
loadAuthData(authenticator);
|
|
93
|
-
|
|
94
|
-
try {
|
|
95
|
-
const success = authenticator.registerUser(username, password);
|
|
96
|
-
if (success) {
|
|
97
|
-
saveAuthData(authenticator);
|
|
98
|
-
console.log(`[SUCCESS] User '${username}' registered successfully`);
|
|
99
|
-
} else {
|
|
100
|
-
console.log(`[ERROR] Username '${username}' already exists`);
|
|
101
|
-
process.exit(1);
|
|
102
|
-
}
|
|
103
|
-
} catch (error) {
|
|
104
|
-
console.log(`[ERROR] Registration failed: ${error.message}`);
|
|
105
|
-
process.exit(1);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Handle user login.
|
|
111
|
-
* @param {string} username - The username to login
|
|
112
|
-
* @param {string} password - The password for the user
|
|
113
|
-
*/
|
|
114
|
-
function handleLogin(username, password) {
|
|
115
|
-
const authenticator = new UserAuthenticator();
|
|
116
|
-
loadAuthData(authenticator);
|
|
117
|
-
|
|
118
|
-
const [success, result] = authenticateAndGetToken(
|
|
119
|
-
authenticator,
|
|
120
|
-
username,
|
|
121
|
-
password,
|
|
122
|
-
);
|
|
123
|
-
|
|
124
|
-
if (success) {
|
|
125
|
-
const token = result;
|
|
126
|
-
saveAuthData(authenticator);
|
|
127
|
-
|
|
128
|
-
// Also save the token to a session file for easy access
|
|
129
|
-
const sessionFile = path.join(
|
|
130
|
-
path.dirname(getAuthDataPath()),
|
|
131
|
-
'session.token',
|
|
132
|
-
);
|
|
133
|
-
fs.writeFileSync(sessionFile, token);
|
|
134
|
-
|
|
135
|
-
console.log('[SUCCESS] Login successful');
|
|
136
|
-
console.log(`Session token: ${token}`);
|
|
137
|
-
} else {
|
|
138
|
-
console.log(`[ERROR] Login failed: ${result}`);
|
|
139
|
-
process.exit(1);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* Handle user logout.
|
|
145
|
-
*/
|
|
146
|
-
function handleLogout() {
|
|
147
|
-
const authenticator = new UserAuthenticator();
|
|
148
|
-
loadAuthData(authenticator);
|
|
149
|
-
|
|
150
|
-
// Read the current session token
|
|
151
|
-
const sessionFile = path.join(
|
|
152
|
-
path.dirname(getAuthDataPath()),
|
|
153
|
-
'session.token',
|
|
154
|
-
);
|
|
155
|
-
|
|
156
|
-
if (!fs.existsSync(sessionFile)) {
|
|
157
|
-
console.log('[ERROR] No active session found');
|
|
158
|
-
process.exit(1);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
const token = fs.readFileSync(sessionFile, 'utf8').trim();
|
|
162
|
-
|
|
163
|
-
const success = authenticator.logout(token);
|
|
164
|
-
if (success) {
|
|
165
|
-
saveAuthData(authenticator);
|
|
166
|
-
fs.unlinkSync(sessionFile); // Remove the session file
|
|
167
|
-
console.log('[SUCCESS] Logged out successfully');
|
|
168
|
-
} else {
|
|
169
|
-
console.log('[ERROR] Logout failed: Invalid session');
|
|
170
|
-
process.exit(1);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* Check if user is authenticated.
|
|
176
|
-
*/
|
|
177
|
-
function handleStatus() {
|
|
178
|
-
const authenticator = new UserAuthenticator();
|
|
179
|
-
loadAuthData(authenticator);
|
|
180
|
-
|
|
181
|
-
// Read the current session token
|
|
182
|
-
const sessionFile = path.join(
|
|
183
|
-
path.dirname(getAuthDataPath()),
|
|
184
|
-
'session.token',
|
|
185
|
-
);
|
|
186
|
-
|
|
187
|
-
if (!fs.existsSync(sessionFile)) {
|
|
188
|
-
console.log('[INFO] No active session');
|
|
189
|
-
return;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
const token = fs.readFileSync(sessionFile, 'utf8').trim();
|
|
193
|
-
const username = authenticator.validateSession(token);
|
|
194
|
-
|
|
195
|
-
if (username) {
|
|
196
|
-
console.log(`[INFO] Authenticated as: ${username}`);
|
|
197
|
-
} else {
|
|
198
|
-
console.log('[INFO] Session expired or invalid');
|
|
199
|
-
fs.unlinkSync(sessionFile); // Remove the invalid session file
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
module.exports = {
|
|
204
|
-
handleRegister,
|
|
205
|
-
handleLogin,
|
|
206
|
-
handleLogout,
|
|
207
|
-
handleStatus,
|
|
208
|
-
};
|
|
1
|
+
/**
|
|
2
|
+
* Authentication command handler for the Stigmergy CLI.
|
|
3
|
+
* Provides CLI commands for user registration, login, and session management.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
const fs = require('fs');
|
|
7
|
+
const path = require('path');
|
|
8
|
+
const { UserAuthenticator, authenticateAndGetToken } = require('./auth');
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Get the path to the authentication data file.
|
|
12
|
+
* @returns {string} Path to the auth data file
|
|
13
|
+
*/
|
|
14
|
+
function getAuthDataPath() {
|
|
15
|
+
const homeDir = process.env.HOME || process.env.USERPROFILE;
|
|
16
|
+
const configDir = path.join(homeDir, '.stigmergy');
|
|
17
|
+
|
|
18
|
+
// Create config directory if it doesn't exist
|
|
19
|
+
if (!fs.existsSync(configDir)) {
|
|
20
|
+
fs.mkdirSync(configDir, { recursive: true });
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return path.join(configDir, 'auth.json');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Load authentication data from file.
|
|
28
|
+
* @param {UserAuthenticator} authenticator - The authenticator instance
|
|
29
|
+
*/
|
|
30
|
+
function loadAuthData(authenticator) {
|
|
31
|
+
try {
|
|
32
|
+
const authFile = getAuthDataPath();
|
|
33
|
+
if (fs.existsSync(authFile)) {
|
|
34
|
+
const data = JSON.parse(fs.readFileSync(authFile, 'utf8'));
|
|
35
|
+
|
|
36
|
+
// Load users
|
|
37
|
+
if (data.users) {
|
|
38
|
+
for (const [username, userData] of Object.entries(data.users)) {
|
|
39
|
+
authenticator._users.set(username, userData);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Load sessions
|
|
44
|
+
if (data.sessions) {
|
|
45
|
+
for (const [token, sessionData] of Object.entries(data.sessions)) {
|
|
46
|
+
authenticator._sessions.set(token, sessionData);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
} catch (error) {
|
|
51
|
+
console.warn('[WARN] Could not load authentication data:', error.message);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Save authentication data to file.
|
|
57
|
+
* @param {UserAuthenticator} authenticator - The authenticator instance
|
|
58
|
+
*/
|
|
59
|
+
function saveAuthData(authenticator) {
|
|
60
|
+
try {
|
|
61
|
+
const authFile = getAuthDataPath();
|
|
62
|
+
|
|
63
|
+
// Convert Maps to objects for JSON serialization
|
|
64
|
+
const users = {};
|
|
65
|
+
for (const [username, userData] of authenticator._users.entries()) {
|
|
66
|
+
users[username] = userData;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const sessions = {};
|
|
70
|
+
for (const [token, sessionData] of authenticator._sessions.entries()) {
|
|
71
|
+
sessions[token] = sessionData;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const data = {
|
|
75
|
+
users,
|
|
76
|
+
sessions,
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
fs.writeFileSync(authFile, JSON.stringify(data, null, 2));
|
|
80
|
+
} catch (error) {
|
|
81
|
+
console.warn('[WARN] Could not save authentication data:', error.message);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Handle user registration.
|
|
87
|
+
* @param {string} username - The username to register
|
|
88
|
+
* @param {string} password - The password for the user
|
|
89
|
+
*/
|
|
90
|
+
function handleRegister(username, password) {
|
|
91
|
+
const authenticator = new UserAuthenticator();
|
|
92
|
+
loadAuthData(authenticator);
|
|
93
|
+
|
|
94
|
+
try {
|
|
95
|
+
const success = authenticator.registerUser(username, password);
|
|
96
|
+
if (success) {
|
|
97
|
+
saveAuthData(authenticator);
|
|
98
|
+
console.log(`[SUCCESS] User '${username}' registered successfully`);
|
|
99
|
+
} else {
|
|
100
|
+
console.log(`[ERROR] Username '${username}' already exists`);
|
|
101
|
+
process.exit(1);
|
|
102
|
+
}
|
|
103
|
+
} catch (error) {
|
|
104
|
+
console.log(`[ERROR] Registration failed: ${error.message}`);
|
|
105
|
+
process.exit(1);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Handle user login.
|
|
111
|
+
* @param {string} username - The username to login
|
|
112
|
+
* @param {string} password - The password for the user
|
|
113
|
+
*/
|
|
114
|
+
function handleLogin(username, password) {
|
|
115
|
+
const authenticator = new UserAuthenticator();
|
|
116
|
+
loadAuthData(authenticator);
|
|
117
|
+
|
|
118
|
+
const [success, result] = authenticateAndGetToken(
|
|
119
|
+
authenticator,
|
|
120
|
+
username,
|
|
121
|
+
password,
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
if (success) {
|
|
125
|
+
const token = result;
|
|
126
|
+
saveAuthData(authenticator);
|
|
127
|
+
|
|
128
|
+
// Also save the token to a session file for easy access
|
|
129
|
+
const sessionFile = path.join(
|
|
130
|
+
path.dirname(getAuthDataPath()),
|
|
131
|
+
'session.token',
|
|
132
|
+
);
|
|
133
|
+
fs.writeFileSync(sessionFile, token);
|
|
134
|
+
|
|
135
|
+
console.log('[SUCCESS] Login successful');
|
|
136
|
+
console.log(`Session token: ${token}`);
|
|
137
|
+
} else {
|
|
138
|
+
console.log(`[ERROR] Login failed: ${result}`);
|
|
139
|
+
process.exit(1);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Handle user logout.
|
|
145
|
+
*/
|
|
146
|
+
function handleLogout() {
|
|
147
|
+
const authenticator = new UserAuthenticator();
|
|
148
|
+
loadAuthData(authenticator);
|
|
149
|
+
|
|
150
|
+
// Read the current session token
|
|
151
|
+
const sessionFile = path.join(
|
|
152
|
+
path.dirname(getAuthDataPath()),
|
|
153
|
+
'session.token',
|
|
154
|
+
);
|
|
155
|
+
|
|
156
|
+
if (!fs.existsSync(sessionFile)) {
|
|
157
|
+
console.log('[ERROR] No active session found');
|
|
158
|
+
process.exit(1);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const token = fs.readFileSync(sessionFile, 'utf8').trim();
|
|
162
|
+
|
|
163
|
+
const success = authenticator.logout(token);
|
|
164
|
+
if (success) {
|
|
165
|
+
saveAuthData(authenticator);
|
|
166
|
+
fs.unlinkSync(sessionFile); // Remove the session file
|
|
167
|
+
console.log('[SUCCESS] Logged out successfully');
|
|
168
|
+
} else {
|
|
169
|
+
console.log('[ERROR] Logout failed: Invalid session');
|
|
170
|
+
process.exit(1);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Check if user is authenticated.
|
|
176
|
+
*/
|
|
177
|
+
function handleStatus() {
|
|
178
|
+
const authenticator = new UserAuthenticator();
|
|
179
|
+
loadAuthData(authenticator);
|
|
180
|
+
|
|
181
|
+
// Read the current session token
|
|
182
|
+
const sessionFile = path.join(
|
|
183
|
+
path.dirname(getAuthDataPath()),
|
|
184
|
+
'session.token',
|
|
185
|
+
);
|
|
186
|
+
|
|
187
|
+
if (!fs.existsSync(sessionFile)) {
|
|
188
|
+
console.log('[INFO] No active session');
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const token = fs.readFileSync(sessionFile, 'utf8').trim();
|
|
193
|
+
const username = authenticator.validateSession(token);
|
|
194
|
+
|
|
195
|
+
if (username) {
|
|
196
|
+
console.log(`[INFO] Authenticated as: ${username}`);
|
|
197
|
+
} else {
|
|
198
|
+
console.log('[INFO] Session expired or invalid');
|
|
199
|
+
fs.unlinkSync(sessionFile); // Remove the invalid session file
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
module.exports = {
|
|
204
|
+
handleRegister,
|
|
205
|
+
handleLogin,
|
|
206
|
+
handleLogout,
|
|
207
|
+
handleStatus,
|
|
208
|
+
};
|