mm-math 0.0.8 → 0.0.9

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.
Files changed (4) hide show
  1. package/games.json +29537 -0
  2. package/index.html +35 -23
  3. package/package.json +4 -2
  4. package/users.json +62 -0
package/index.html CHANGED
@@ -235,6 +235,7 @@ button:active {
235
235
  }
236
236
  .btn-cancel:hover { color: #6b8fb5; background: rgba(255,255,255,.04); }
237
237
  </style>
238
+ <script src="https://unpkg.com/bcryptjs@2.4.3/dist/bcrypt.min.js"></script>
238
239
  </head>
239
240
  <body>
240
241
 
@@ -519,7 +520,7 @@ document.getElementById('fUser').addEventListener('keydown', e => {
519
520
  });
520
521
 
521
522
  // ── Login ─────────────────────────────────────────────────────────────────────
522
- const API = 'https://orange-dust-8e2b.jonah-7a0.workers.dev';
523
+ const _onCalc = window.location.hostname === 'calc.moshelab.com';
523
524
 
524
525
  async function doLogin() {
525
526
  const username = document.getElementById('fUser').value.trim();
@@ -537,33 +538,44 @@ async function doLogin() {
537
538
  errEl.textContent = '';
538
539
 
539
540
  try {
540
- const res = await fetch(API + '/api/login', {
541
- method: 'POST',
542
- headers: { 'Content-Type': 'application/json' },
543
- body: JSON.stringify({ username, password }),
544
- });
545
- const data = await res.json();
546
- data.ok = res.ok; data.status = res.status;
547
-
548
- if (!data.ok || !data.success) {
549
- errEl.textContent = data.status === 429 || (data.error || '').includes('Too many')
550
- ? 'Too many attempts. Wait 60 seconds.'
551
- : 'Invalid username or password.';
552
- btn.disabled = false;
553
- btn.textContent = 'Sign In';
554
- return;
541
+ let rank, token, forcePasswordChange;
542
+
543
+ if (_onCalc) {
544
+ const res = await fetch('/api/login', {
545
+ method: 'POST',
546
+ headers: { 'Content-Type': 'application/json' },
547
+ body: JSON.stringify({ username, password }),
548
+ });
549
+ const data = await res.json();
550
+ if (!res.ok || !data.success) {
551
+ errEl.textContent = res.status === 429 || (data.error || '').includes('Too many')
552
+ ? 'Too many attempts. Wait 60 seconds.'
553
+ : 'Invalid username or password.';
554
+ btn.disabled = false; btn.textContent = 'Sign In'; return;
555
+ }
556
+ rank = data.rank; token = data.token; forcePasswordChange = !!data.forcePasswordChange;
557
+ } else {
558
+ const users = await fetch('./users.json').then(r => r.json());
559
+ const user = users.find(u => u.username === username);
560
+ if (!user || !dcodeIO.bcrypt.compareSync(password, user.password)) {
561
+ errEl.textContent = 'Invalid username or password.';
562
+ btn.disabled = false; btn.textContent = 'Sign In'; return;
563
+ }
564
+ rank = user.rank;
565
+ token = (crypto.randomUUID ? crypto.randomUUID() : Math.random().toString(36).slice(2) + Math.random().toString(36).slice(2));
566
+ forcePasswordChange = false;
555
567
  }
556
568
 
557
569
  sessionStorage.setItem('mm_auth', 'true');
558
- sessionStorage.setItem('mm_token', data.token);
559
- sessionStorage.setItem('mm_rank', data.rank);
570
+ sessionStorage.setItem('mm_token', token);
571
+ sessionStorage.setItem('mm_rank', rank);
560
572
  sessionStorage.setItem('mm_user', username);
561
- sessionStorage.setItem('mm_force_change', data.forcePasswordChange ? 'true' : 'false');
573
+ sessionStorage.setItem('mm_force_change', forcePasswordChange ? 'true' : 'false');
562
574
 
563
- if (data.forcePasswordChange) window.location.href = './change-password.html';
564
- else if (data.rank === 'administrator') window.location.href = './admin.html';
565
- else if (data.rank === 'admin') window.location.href = './control-panel.html';
566
- else window.location.href = './browse.html';
575
+ if (forcePasswordChange) window.location.href = './change-password.html';
576
+ else if (rank === 'administrator') window.location.href = './admin.html';
577
+ else if (rank === 'admin') window.location.href = './control-panel.html';
578
+ else window.location.href = './browse.html';
567
579
  } catch (err) {
568
580
  errEl.textContent = err && err.message ? err.message : String(err);
569
581
  btn.disabled = false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mm-math",
3
- "version": "0.0.8",
3
+ "version": "0.0.9",
4
4
  "description": "STEM educational toolkit",
5
5
  "main": "index.html",
6
6
  "files": [
@@ -15,7 +15,9 @@
15
15
  "version.txt",
16
16
  "assets/",
17
17
  "css/",
18
- "js/"
18
+ "js/",
19
+ "users.json",
20
+ "games.json"
19
21
  ],
20
22
  "scripts": {
21
23
  "start": "node api.js"
package/users.json ADDED
@@ -0,0 +1,62 @@
1
+ [
2
+ {
3
+ "username": "owner",
4
+ "password": "$2b$12$pv3OKADBaxJdCPEni5KHJexzvuSxQZQU0wdZ03OogqGbg1/UbPjc2",
5
+ "rank": "administrator",
6
+ "forcePasswordChange": false
7
+ },
8
+ {
9
+ "username": "Zach",
10
+ "password": "$2b$12$Mmz/l6N5rbwGOzYVoOMHbeVjQtpn.dSFQxoDhM2EJF9PJXesASxDC",
11
+ "rank": "admin",
12
+ "forcePasswordChange": true
13
+ },
14
+ {
15
+ "username": "Anthony",
16
+ "password": "$2b$12$GOdPip91LXzin0tm405YR.czj4zVDHcKNugvBDASfuyeNs20g0OkS",
17
+ "rank": "admin",
18
+ "forcePasswordChange": true
19
+ },
20
+ {
21
+ "username": "Viraj",
22
+ "password": "$2b$12$Tq60W3D7ti8l3LOApZP1keKy8aulE9zv.es0dbOxyQ61BF/g1iFJO",
23
+ "rank": "user",
24
+ "forcePasswordChange": true
25
+ },
26
+ {
27
+ "username": "Blake",
28
+ "password": "$2b$12$5QX1SvmJVDQuP/Ek3IOmVu85Fh5Gp3rgKNUREZGuONIc5zp7quIb.",
29
+ "rank": "admin",
30
+ "forcePasswordChange": true
31
+ },
32
+ {
33
+ "username": "Niko",
34
+ "password": "$2b$12$orOTbzLeA.Dzw7E.fRuPd.IE52xQahOF1oX57xVlGmUeNSRvB8sLi",
35
+ "rank": "admin",
36
+ "forcePasswordChange": true
37
+ },
38
+ {
39
+ "username": "Sebastian",
40
+ "password": "$2b$12$gA9e471aAPqqtkxMkiUsou2SWwMEPHF1.rYTEqarwvFWPHiavJxfW",
41
+ "rank": "administrator",
42
+ "forcePasswordChange": true
43
+ },
44
+ {
45
+ "username": "Logan",
46
+ "password": "$2b$12$ivEJU6D/nOXXg3WP93TuUusjOJaLFc2uEDvWm9IDRzINMFhoxm5cq",
47
+ "rank": "user",
48
+ "forcePasswordChange": true
49
+ },
50
+ {
51
+ "username": "Spencer",
52
+ "password": "$2b$12$Ru3Vz/.XeOO.xJRD3NW6rOK5LIpXH4nOFGKLf6W36nU5inUM0s27m",
53
+ "rank": "admin",
54
+ "forcePasswordChange": true
55
+ },
56
+ {
57
+ "username": "Finn",
58
+ "password": "$2b$12$UKA3fZnBItyMSME0y9Jmsu0eN4iXZmqUAY0gVPvB0bonBvWtCo3Gy",
59
+ "rank": "admin",
60
+ "forcePasswordChange": true
61
+ }
62
+ ]