noho-platform 1.0.0
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/.noho_session.json +6 -0
- package/login.js +49 -0
- package/noho-cli.js +123 -0
- package/noho-dashboard.html +891 -0
- package/noho-lib.js +431 -0
- package/noho-server.js +441 -0
- package/noho_data/pages/3f550d44-2383-45cd-bd12-96d5c16f7fb7_1429be93890e6120.json +21 -0
- package/noho_data/users/3444499b-de5a-4931-b802-e02a054ef0c1.json +20 -0
- package/noho_data/users/3f550d44-2383-45cd-bd12-96d5c16f7fb7.json +22 -0
- package/noho_data/users/d4555ad8-9324-4ad3-a485-c234f17c2708.json +20 -0
- package/package.json +22 -0
- package/test-lib.js +56 -0
- package/test_data/pages/a019aa48-0caf-478f-927e-266c812eae10_10022dfa5d34936d.json +24 -0
- package/test_data/users/a019aa48-0caf-478f-927e-266c812eae10.json +22 -0
package/login.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
const NOHOLibrary = require('./noho-lib');
|
|
2
|
+
const readline = require('readline');
|
|
3
|
+
|
|
4
|
+
const rl = readline.createInterface({
|
|
5
|
+
input: process.stdin,
|
|
6
|
+
output: process.stdout
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
const question = (q) => new Promise(resolve => rl.question(q, resolve));
|
|
10
|
+
|
|
11
|
+
async function loginCLI() {
|
|
12
|
+
console.log('🔐 NOHO Login\n');
|
|
13
|
+
|
|
14
|
+
const lib = new NOHOLibrary({
|
|
15
|
+
dbPath: './noho_data'
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
await new Promise(r => setTimeout(r, 500));
|
|
19
|
+
|
|
20
|
+
const email = await question('Email: ');
|
|
21
|
+
const password = await question('Password: ');
|
|
22
|
+
|
|
23
|
+
try {
|
|
24
|
+
const result = await lib.loginUser(email, password);
|
|
25
|
+
console.log('\n✅ Login successful!');
|
|
26
|
+
console.log('Token:', result.token);
|
|
27
|
+
console.log('Username:', result.user.username);
|
|
28
|
+
console.log('API Key:', result.user.apiKey);
|
|
29
|
+
|
|
30
|
+
// حفظ في ملف للاستخدام لاحقاً
|
|
31
|
+
const fs = require('fs');
|
|
32
|
+
const session = {
|
|
33
|
+
token: result.token,
|
|
34
|
+
apiKey: result.user.apiKey,
|
|
35
|
+
username: result.user.username,
|
|
36
|
+
userId: result.user.id,
|
|
37
|
+
loginTime: new Date().toISOString()
|
|
38
|
+
};
|
|
39
|
+
fs.writeFileSync('.noho_session.json', JSON.stringify(session, null, 2));
|
|
40
|
+
console.log('\n💾 Session saved to .noho_session.json');
|
|
41
|
+
|
|
42
|
+
} catch (error) {
|
|
43
|
+
console.log('\n❌ Error:', error.message);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
rl.close();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
loginCLI();
|
package/noho-cli.js
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
const NOHOLibrary = require('./noho-lib');
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
|
|
5
|
+
const SESSION_FILE = '.noho_session.json';
|
|
6
|
+
|
|
7
|
+
function loadSession() {
|
|
8
|
+
try {
|
|
9
|
+
return JSON.parse(fs.readFileSync(SESSION_FILE, 'utf8'));
|
|
10
|
+
} catch {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function saveSession(data) {
|
|
16
|
+
fs.writeFileSync(SESSION_FILE, JSON.stringify(data, null, 2));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async function main() {
|
|
20
|
+
const args = process.argv.slice(2);
|
|
21
|
+
const command = args[0];
|
|
22
|
+
|
|
23
|
+
const lib = new NOHOLibrary({ dbPath: './noho_data' });
|
|
24
|
+
await new Promise(r => setTimeout(r, 500));
|
|
25
|
+
|
|
26
|
+
switch(command) {
|
|
27
|
+
case 'register':
|
|
28
|
+
const [username, email, password] = args.slice(1);
|
|
29
|
+
if (!username || !email || !password) {
|
|
30
|
+
console.log('Usage: node noho-cli.js register <username> <email> <password>');
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const user = await lib.registerUser(email, password, username);
|
|
34
|
+
console.log('✅ User created:', user.username);
|
|
35
|
+
console.log('API Key:', user.apiKey);
|
|
36
|
+
saveSession({
|
|
37
|
+
apiKey: user.apiKey,
|
|
38
|
+
username: user.username,
|
|
39
|
+
userId: user.userId
|
|
40
|
+
});
|
|
41
|
+
break;
|
|
42
|
+
|
|
43
|
+
case 'login':
|
|
44
|
+
const [loginEmail, loginPass] = args.slice(1);
|
|
45
|
+
if (!loginEmail || !loginPass) {
|
|
46
|
+
console.log('Usage: node noho-cli.js login <email> <password>');
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const login = await lib.loginUser(loginEmail, loginPass);
|
|
50
|
+
console.log('✅ Logged in as:', login.user.username);
|
|
51
|
+
console.log('Token:', login.token);
|
|
52
|
+
saveSession({
|
|
53
|
+
token: login.token,
|
|
54
|
+
apiKey: login.user.apiKey,
|
|
55
|
+
username: login.user.username,
|
|
56
|
+
userId: login.user.id
|
|
57
|
+
});
|
|
58
|
+
break;
|
|
59
|
+
|
|
60
|
+
case 'whoami':
|
|
61
|
+
const session = loadSession();
|
|
62
|
+
if (!session) {
|
|
63
|
+
console.log('❌ Not logged in. Use: login or register');
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
console.log('👤 Logged in as:', session.username);
|
|
67
|
+
console.log('API Key:', session.apiKey);
|
|
68
|
+
break;
|
|
69
|
+
|
|
70
|
+
case 'create-page':
|
|
71
|
+
const sess = loadSession();
|
|
72
|
+
if (!sess) {
|
|
73
|
+
console.log('❌ Login first');
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const [route, ...codeParts] = args.slice(1);
|
|
77
|
+
const code = codeParts.join(' ');
|
|
78
|
+
if (!route || !code) {
|
|
79
|
+
console.log('Usage: node noho-cli.js create-page <route> <code>');
|
|
80
|
+
console.log('Example: node noho-cli.js create-page /hello \'res.send("<h1>Hi</h1>")\'');
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
const page = await lib.createPage(sess.userId, route, code, { public: true });
|
|
84
|
+
console.log('✅ Page created:', page.route);
|
|
85
|
+
console.log('URL: http://localhost:5000' + page.route);
|
|
86
|
+
break;
|
|
87
|
+
|
|
88
|
+
case 'list-pages':
|
|
89
|
+
const s = loadSession();
|
|
90
|
+
if (!s) {
|
|
91
|
+
console.log('❌ Login first');
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
const userData = lib.users.get(s.userId);
|
|
95
|
+
console.log('📄 Pages for', s.username + ':');
|
|
96
|
+
userData.pages.forEach(pid => {
|
|
97
|
+
const p = lib.pages.get(pid);
|
|
98
|
+
if (p) {
|
|
99
|
+
console.log(' -', p.route, '(Views:', p.stats.views + ')');
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
break;
|
|
103
|
+
|
|
104
|
+
default:
|
|
105
|
+
console.log(`
|
|
106
|
+
🚀 NOHO CLI
|
|
107
|
+
|
|
108
|
+
Commands:
|
|
109
|
+
register <username> <email> <password> - Create account
|
|
110
|
+
login <email> <password> - Login
|
|
111
|
+
whoami - Show current user
|
|
112
|
+
create-page <route> <code> - Create new page
|
|
113
|
+
list-pages - List your pages
|
|
114
|
+
|
|
115
|
+
Examples:
|
|
116
|
+
node noho-cli.js register ahmed ahmed@test.com 12345678
|
|
117
|
+
node noho-cli.js login ahmed@test.com 12345678
|
|
118
|
+
node noho-cli.js create-page /welcome 'res.send("<h1>Hello</h1>")'
|
|
119
|
+
`);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
main().catch(console.error);
|