create-lupine 1.3.0 → 1.3.2

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 (29) hide show
  1. package/README.md +1 -1
  2. package/index.js +16 -8
  3. package/package.json +1 -1
  4. package/templates/common/.agents/skills/lupine-framework/references/native-apps.md +3 -0
  5. package/templates/common/.env.development +2 -0
  6. package/templates/common/_env +4 -3
  7. package/templates/lupine-template-fullstack-note/api/src/service/user-api.ts +2 -2
  8. package/templates/lupine-template-fullstack-note/app/src/shell/api.ts +10 -0
  9. package/templates/lupine-template-fullstack-note/app/src/shell/locales/ja.ts +1 -0
  10. package/templates/lupine-template-fullstack-note/app/src/shell/locales/zh-CN.ts +1 -0
  11. package/templates/lupine-template-fullstack-note/lupine.json +15 -0
  12. package/templates/lupine-template-fullstack-note/web/src/lupine-template-fullstack-note/404.html +35 -0
  13. package/templates/lupine-template-fullstack-note/web/src/lupine-template-fullstack-note/assets/favicon.ico +0 -0
  14. package/templates/lupine-template-fullstack-note/web/src/lupine-template-fullstack-note/assets/og-image.png +0 -0
  15. package/templates/lupine-template-fullstack-note/web/src/lupine-template-fullstack-note/index.html +39 -0
  16. package/templates/lupine-template-fullstack-note/web/src/lupine-template-fullstack-note/index.tsx +16 -0
  17. package/templates/lupine-template-fullstack-starter/README.md +2 -1
  18. package/templates/lupine-template-fullstack-starter/api/resources/install.mysql.sql +2 -2
  19. package/templates/lupine-template-fullstack-starter/api/resources/install.sqlite.sql +101 -75
  20. package/templates/lupine-template-fullstack-starter/api/src/service/contact-api.ts +2 -2
  21. package/templates/lupine-template-fullstack-starter/api/src/service/user-api.ts +61 -41
  22. package/templates/lupine-template-fullstack-starter/app/src/shell/api.ts +10 -0
  23. package/templates/lupine-template-fullstack-starter/app/src/shell/texts.ts +1 -1
  24. package/templates/lupine-template-fullstack-starter/lupine.json +15 -0
  25. package/templates/lupine-template-fullstack-starter/web/src/lupine-template-fullstack-starter/404.html +35 -0
  26. package/templates/lupine-template-fullstack-starter/web/src/lupine-template-fullstack-starter/assets/favicon.ico +0 -0
  27. package/templates/lupine-template-fullstack-starter/web/src/lupine-template-fullstack-starter/assets/og-image.png +0 -0
  28. package/templates/lupine-template-fullstack-starter/web/src/lupine-template-fullstack-starter/index.html +39 -0
  29. package/templates/lupine-template-fullstack-starter/web/src/lupine-template-fullstack-starter/index.tsx +17 -0
package/README.md CHANGED
@@ -26,6 +26,6 @@ A project has the app in `apps/my-app/app`, the page of the site in `apps/my-app
26
26
 
27
27
  `npx create-lupine --add-app <name>`, in the folder of a project, adds one more app from a template (`apps/<name>`, with its scripts `npm run <name>:run-mac` ...) and prints what to add to `.env` (`APPS`, `DOMAINS:<name>`); `.env` itself isn't changed.
28
28
 
29
- The scripts of a new project: `npm run run-mac`, `run-ios`, `run-android`, `run-exe` (build and start the app), `build-android` (the apk for the store), `bump` (the next version), `icons` (the icons of the site from the icon of the app), `release` (a folder for the server in `dist/release/<name>`).
29
+ The scripts of a new project: `npm run run-mac`, `run-ios`, `run-android`, `run-exe` (build and start the app), `build-android` (the apk for the store), `build-ios` and `upload-ios` (the .ipa for the App Store and TestFlight), `open-ios` and `open-android` (the project in Xcode / Android Studio), `bump` (the next version), `icons` (the icons of the site from the icon of the app), `release` (a folder for the server in `dist/release/<name>`).
30
30
 
31
31
  MIT.
package/index.js CHANGED
@@ -231,6 +231,11 @@ function appScripts(appName, prefix = '') {
231
231
  [`${prefix}build-android`]: `lupine-native android --release ${app}`,
232
232
  [`${prefix}run-android`]: `lupine-native android --install --run ${app}`,
233
233
  [`${prefix}run-ios`]: `lupine-native ios --install --run ${app}`,
234
+ // Xcode and Android Studio; the App Store (--team=<Apple team> or LUPINE_TEAM; the API key for uploads in dist/cert)
235
+ [`${prefix}open-ios`]: `lupine-native ios --open --release --device ${app}`,
236
+ [`${prefix}build-ios`]: `lupine-native ios --ipa --release --device ${app}`,
237
+ [`${prefix}upload-ios`]: `lupine-native ios --upload ${app}`,
238
+ [`${prefix}open-android`]: `lupine-native android --open --release ${app}`,
234
239
  [`${prefix}run-mac`]: `lupine-native macos --run ${app}`,
235
240
  [`${prefix}run-exe`]: `lupine-native windows --run ${app}`,
236
241
  };
@@ -313,13 +318,13 @@ async function addApp(name, template, versions) {
313
318
  async function init() {
314
319
  console.log('Fetching latest versions...');
315
320
  const versions = {
316
- 'lupine.api': getLatestVersion('lupine.api', '^1.2.42'),
317
- 'lupine.web': getLatestVersion('lupine.web', '^1.3.0'),
318
- 'lupine.core': getLatestVersion('lupine.core', '^1.1.1'),
319
- 'lupine.web.components': getLatestVersion('lupine.web.components', '^1.3.1'),
320
- 'lupine.native.core': getLatestVersion('lupine.native.core', '^1.1.0'),
321
+ 'lupine.api': getLatestVersion('lupine.api', '^1.2.44'),
322
+ 'lupine.web': getLatestVersion('lupine.web', '^1.3.1'),
323
+ 'lupine.core': getLatestVersion('lupine.core', '^1.1.2'),
324
+ 'lupine.web.components': getLatestVersion('lupine.web.components', '^1.3.2'),
325
+ 'lupine.native.core': getLatestVersion('lupine.native.core', '^1.1.1'),
321
326
  'lupine.native.components': getLatestVersion('lupine.native.components', '^1.1.1'),
322
- 'lupine.press': getLatestVersion('lupine.press', '^1.3.0'),
327
+ 'lupine.press': getLatestVersion('lupine.press', '^1.3.1'),
323
328
  };
324
329
 
325
330
  if (argv['update-version']) {
@@ -415,6 +420,8 @@ async function init() {
415
420
  copyDir(commonDir, root);
416
421
  fs.renameSync(path.join(root, '_gitignore'), path.join(root, '.gitignore'));
417
422
  fs.renameSync(path.join(root, '_env'), path.join(root, '.env'));
423
+ // .env gets the keys and passwords of the project: only its owner reads it
424
+ fs.chmodSync(path.join(root, '.env'), 0o600);
418
425
 
419
426
  const appName = path.basename(root);
420
427
  const targetAppDir = scaffoldApp(root, appName, templateObj);
@@ -431,7 +438,7 @@ async function init() {
431
438
  'start-production': 'node dist/server_root/server/server-loader.js --env=.env.production',
432
439
  // the apps: npm run native -- macos --app=<the folder in apps/> --run (ios, android, windows, web; test macos)
433
440
  native: 'lupine-native',
434
- // the app: npm run run-android, run-ios, run-mac, run-exe, build-android, bump, icons
441
+ // the app: npm run run-android, run-ios, run-mac, run-exe, build-android, build-ios, upload-ios, open-ios, open-android, bump, icons
435
442
  ...appScripts(appName),
436
443
  // a folder with what the server needs (dist/release/<name>): copy it to the server
437
444
  release: `lupine-build --env=.env.production --dev=0 --obfuscate=0 --release=dist/release/${appName}`,
@@ -481,7 +488,8 @@ async function init() {
481
488
  });
482
489
 
483
490
  envContent = envContent.replace(/{APP-NAME}/g, appName);
484
- fs.writeFileSync(path.join(root, '.env'), envContent);
491
+ fs.writeFileSync(path.join(root, '.env'), envContent, { mode: 0o600 });
492
+ fs.chmodSync(path.join(root, '.env'), 0o600);
485
493
  }
486
494
 
487
495
  console.log(`\nDone. Now run:\n`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-lupine",
3
- "version": "1.3.0",
3
+ "version": "1.3.2",
4
4
  "description": "Scaffolding tool for Lupine.js projects",
5
5
  "bin": {
6
6
  "create-lupine": "index.js"
@@ -159,6 +159,9 @@ npx lupine-native android --app=apps/my-app --run --serial=<adb device>
159
159
  npx lupine-native android --app=apps/my-app --release --install # onto a connected phone: uses a build that is there or builds; asks for the device if several
160
160
  npx lupine-native devices # connected phones (Android, iOS)
161
161
  npx lupine-native bump --app=my-app # store release: version x.y.z -> x.y.(z+1), build + 1; the code reads APP_VERSION
162
+ npx lupine-native ios --app=apps/my-app --ipa --release --device --team=<team> # App Store: archive, .ipa (first time --provision)
163
+ npx lupine-native ios --app=apps/my-app --upload # newest .ipa to App Store Connect / TestFlight; API key in dist/cert (AuthKey_<id>.p8, appstore.json {keyId, issuerId})
164
+ npx lupine-native ios --app=apps/my-app --open --release --device --team=<team> # Xcode project (android --open: Android Studio); bundles the JS before each build there; --rebuild after lupineNative changes
162
165
  npx lupine-native windows --app=apps/my-app --run # on a Mac or Linux --run opens it in Wine
163
166
  npx lupine-native docker android --app=apps/my-app # builds in Docker, nothing installed
164
167
  ```
@@ -5,3 +5,5 @@
5
5
  WEB.NODE_ENV=development
6
6
  NODE_ENV=development
7
7
  LOG_LEVEL=debug
8
+ # development only: the server may call APIs that have a certificate of mkcert
9
+ NODE_TLS_REJECT_UNAUTHORIZED=0
@@ -13,7 +13,8 @@ HTTPS_PORT=11083
13
13
  #'127.0.0.1' or for all ips: "::"
14
14
  BIND_IP=0.0.0.0
15
15
 
16
- NODE_TLS_REJECT_UNAUTHORIZED=0
16
+ # NODE_TLS_REJECT_UNAUTHORIZED=0 (certificates not checked): in .env.development only, never here (.env.production imports
17
+ # this file, and lupine-build --deploy refuses to send the key without a checked certificate)
17
18
 
18
19
  LOG_FOLDER=./dist/log
19
20
  LOG_FILENAME=log-%index%.log
@@ -64,8 +65,8 @@ DOMAINS:{APP-NAME}=
64
65
  # mkcert example.com "*.example.com" localhost 127.0.0.1 ::1
65
66
  SSL_KEY_PATH=dist/example.com+4-key.pem
66
67
  SSL_CRT_PATH=dist/example.com+4.pem
67
- HTTPS_KEY_PATH:{APP-NAME}=dist/example.com+4-key.pem
68
- HTTPS_CRT_PATH:{APP-NAME}=dist/example.com+4.pem
68
+ SSL_KEY_PATH:{APP-NAME}=dist/example.com+4-key.pem
69
+ SSL_CRT_PATH:{APP-NAME}=dist/example.com+4.pem
69
70
 
70
71
  DB_TYPE=sqlite
71
72
  SQLITE_FILENAME=sqlite3.db
@@ -129,7 +129,7 @@ export const register = async (req: ServerRequest, res: ServerResponse) => {
129
129
  const d = await db();
130
130
  const taken = () => fail(req, res, 409, 'username_taken', 'This user name is taken.');
131
131
  if ((await d.select('SELECT id FROM $__account WHERE username = ?', [username])).length) return taken();
132
- const password = CryptoUtils.hashPassword(data.password);
132
+ const password = await CryptoUtils.hashPasswordAsync(data.password);
133
133
  let id: number;
134
134
  try {
135
135
  id = insertedId(await d.execute('INSERT INTO $__account (username, password, created_at) VALUES (?, ?, ?)', [username, password, now()]));
@@ -160,7 +160,7 @@ export const login = async (req: ServerRequest, res: ServerResponse) => {
160
160
  if (minutes) return fail(req, res, 429, 'too_many_attempts', `Too many failed sign-ins. Try again in ${minutes} minutes.`, { minutes });
161
161
  const d = await db();
162
162
  const [a] = await d.select<Account>('SELECT id, username, password FROM $__account WHERE username = ?', [username]);
163
- const valid = CryptoUtils.verifyPassword(password, a ? String(a.password) : NOBODY);
163
+ const valid = await CryptoUtils.verifyPasswordAsync(password, a ? String(a.password) : NOBODY);
164
164
  if (!a || !valid) {
165
165
  await recordFailure(username);
166
166
  return failed();
@@ -45,10 +45,19 @@ export const setServerAddress = (address: string) => {
45
45
  base = address.replace(/\/+$/, '');
46
46
  };
47
47
 
48
+ // the copy for GitHub Pages (web/src/lupine-template-fullstack-note): the app without a server, every call answers
49
+ // no_server and the app says why
50
+ let noServer = false;
51
+ /** no server: sign-in and notes say that this is a demo */
52
+ export const setNoServer = () => {
53
+ noServer = true;
54
+ };
55
+
48
56
  /** The text of an answer for the user, by its code. A code the app doesn't know: the message of the API. */
49
57
  export const messageOf = (a: Answer): string => {
50
58
  switch (a.code) {
51
59
  case 'offline': return t('api.offline', 'The server cannot be reached');
60
+ case 'no_server': return t('api.no_server', 'This is only a static page, without a back-end server: sign-in and notes work in a project made from this template');
52
61
  case 'bad_answer': return t('api.bad_answer', 'Unexpected answer of the server ({status})', { status: a.httpStatus ?? '?' });
53
62
  case 'bad_request': return t('api.bad_request', 'The server did not understand the request');
54
63
  case 'bad_username': return t('api.bad_username', 'User name: 3 to 50 characters (letters, digits, _ . @ -)');
@@ -93,6 +102,7 @@ const forget = () => {
93
102
  };
94
103
 
95
104
  const call = async (path: string, body?: object): Promise<Answer> => {
105
+ if (noServer) return { status: 'error', code: 'no_server' };
96
106
  const headers: { [name: string]: string } = { Accept: 'application/json' };
97
107
  if (body) headers['Content-Type'] = 'application/json';
98
108
  if (native) {
@@ -60,6 +60,7 @@ export const ja = {
60
60
  // the texts of the codes of the API (shell/api.ts: messageOf)
61
61
  api: {
62
62
  offline: 'サーバーに接続できません',
63
+ no_server: 'これは静的なページで、バックエンドのサーバーはありません。このテンプレートから作ったプロジェクトでログインとメモが使えます',
63
64
  bad_answer: 'サーバーから予期しない応答がありました({status})',
64
65
  bad_request: 'サーバーがリクエストを理解できませんでした',
65
66
  bad_username: 'ユーザー名:3〜50 文字(英字、数字、_ . @ -)',
@@ -60,6 +60,7 @@ export const zhCN = {
60
60
  // the texts of the codes of the API (shell/api.ts: messageOf)
61
61
  api: {
62
62
  offline: '无法连接服务器',
63
+ no_server: '这只是静态网页,没有后端服务器:用这个模板创建项目后,就能登录和保存笔记',
63
64
  bad_answer: '服务器返回了意外的结果({status})',
64
65
  bad_request: '服务器无法理解该请求',
65
66
  bad_username: '用户名:3 到 50 个字符(字母、数字、_ . @ -)',
@@ -7,6 +7,11 @@
7
7
  "index": "web/src/index.tsx",
8
8
  "html": "web/src/index.html",
9
9
  "outdir": "/"
10
+ },
11
+ {
12
+ "index": "web/src/lupine-template-fullstack-note/index.tsx",
13
+ "html": "web/src/lupine-template-fullstack-note/index.html",
14
+ "outdir": "/lupine-template-fullstack-note"
10
15
  }
11
16
  ],
12
17
  "apiEntryPoint": "api/src/index.ts",
@@ -20,6 +25,16 @@
20
25
  "env": "all",
21
26
  "from": "api/resources",
22
27
  "to": "data/resources"
28
+ },
29
+ {
30
+ "env": "all",
31
+ "from": "web/src/lupine-template-fullstack-note/assets",
32
+ "to": "web/lupine-template-fullstack-note/assets"
33
+ },
34
+ {
35
+ "env": "all",
36
+ "from": "web/src/lupine-template-fullstack-note/404.html",
37
+ "to": "web/lupine-template-fullstack-note/404.html"
23
38
  }
24
39
  ]
25
40
  }
@@ -0,0 +1,35 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
+ <title>Page Not Found</title>
7
+ <style>
8
+ main {
9
+ display: flex;
10
+ height: 100vh;
11
+ justify-content: center;
12
+ align-items: center;
13
+ flex-direction: column;
14
+ }
15
+ .header404 {
16
+ font-size: 48px;
17
+ }
18
+ </style>
19
+ <script type="text/javascript">
20
+ // Single Page Apps for GitHub Pages, change all "/lupine-template-fullstack-note/" to your github project name
21
+ if (window.location.pathname.includes('/lupine-template-fullstack-note/')) {
22
+ window.location.href = '/lupine-template-fullstack-note/?redirect=' + window.location.pathname;
23
+ }
24
+ </script>
25
+ </head>
26
+ <body>
27
+ <main>
28
+ <h4 class="header404">404</h4>
29
+ <div class="content-404">Uh-oh! We couldn't find the page you are looking for.</div>
30
+ <p>
31
+ <a href="/lupine-template-fullstack-note/">Check our home page</a>
32
+ </p>
33
+ </main>
34
+ </body>
35
+ </html>
@@ -0,0 +1,39 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <title>Lupine Template Fullstack Note</title>
6
+ <meta name="description" content="Lupine Template Fullstack Note - sign-in and notes kept on the server, for iOS, Android, macOS, Windows and the web: tabs, a side menu, settings, themes, languages. This page is static, without the server. Powered by Lupine.js." />
7
+
8
+ <!-- Open Graph / Facebook -->
9
+ <meta property="og:type" content="website" />
10
+ <meta property="og:url" content="https://uuware.github.io/lupine-template-fullstack-note/" />
11
+ <meta property="og:title" content="Lupine Template Fullstack Note (Powered by Lupine.js)" />
12
+ <meta property="og:description" content="Lupine Template Fullstack Note - sign-in and notes kept on the server, for iOS, Android, macOS, Windows and the web: tabs, a side menu, settings, themes, languages. This page is static, without the server. Powered by Lupine.js." />
13
+ <meta property="og:image" content="https://uuware.github.io/lupine-template-fullstack-note/assets/og-image.png" />
14
+
15
+ <!-- Twitter -->
16
+ <meta property="twitter:card" content="summary_large_image" />
17
+ <meta property="twitter:url" content="https://uuware.github.io/lupine-template-fullstack-note/" />
18
+ <meta property="twitter:title" content="Lupine Template Fullstack Note (Powered by Lupine.js)" />
19
+ <meta property="twitter:description" content="Lupine Template Fullstack Note - sign-in and notes kept on the server, for iOS, Android, macOS, Windows and the web: tabs, a side menu, settings, themes, languages. This page is static, without the server. Powered by Lupine.js." />
20
+ <meta property="twitter:image" content="https://uuware.github.io/lupine-template-fullstack-note/assets/og-image.png" />
21
+
22
+ <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" />
23
+ <!--META-ENV-START-->
24
+ <!--META-ENV-END-->
25
+ <link rel="shortcut icon" href="{SUBDIR}/assets/favicon.ico?t={hash}" type="image/x-icon" />
26
+ <style>
27
+ html,
28
+ body,
29
+ .lupine-root {
30
+ height: 100%;
31
+ margin: 0;
32
+ }
33
+ </style>
34
+ <script defer src="{SUBDIR}/index.js?t={hash}"></script>
35
+ </head>
36
+ <body>
37
+ <div class="lupine-root"></div>
38
+ </body>
39
+ </html>
@@ -0,0 +1,16 @@
1
+ // lupine.native.core/web first: the storage of the browser, which the controls read when they start
2
+ import { runApp } from 'lupine.native.core/web';
3
+ import { router, Toast } from 'lupine.native.components';
4
+ import { App } from '../../../app/src/app';
5
+ import { messageOf, setNoServer } from '../../../app/src/shell/api';
6
+
7
+ // The copy for GitHub Pages (https://uuware.github.io/lupine-template-fullstack-note/): the app alone, a static page
8
+ // without the server, so sign-in and notes only say that (setNoServer). The address bar follows its pages under the
9
+ // folder of the project; 404.html sends an address that GitHub doesn't have back to this page (?redirect=), and the
10
+ // router opens it. The server of the site only loads this file, so the app starts in the browser.
11
+ if (typeof document === 'object') {
12
+ setNoServer();
13
+ router.followUrl({ paths: true, base: '/lupine-template-fullstack-note' });
14
+ runApp(App, document.querySelector('.lupine-root') as HTMLElement);
15
+ setTimeout(() => Toast.info(messageOf({ status: 'error', code: 'no_server' }), 6000), 800);
16
+ }
@@ -59,7 +59,8 @@ In the browser the app always calls the site it comes from, and `WEB.API_BASE_UR
59
59
  - In the browser the API sets the httpOnly cookie `_token` when you sign in, so the scripts of the page never hold the token.
60
60
  - A native app has no cookie store. It keeps the token from the sign-in answer in `storage` and sends it as `Cookie: _token=...`. The API puts the token in the answer only for requests without `Origin`, which browsers always send with a POST, so a script in a page can't get it from there either. Signing out removes it and calls `/api/logout`.
61
61
  - The admin pages are web only. On a phone "Admin pages" opens the site in the browser, where you sign in again.
62
- - Writing routes are POST only and check the session. Uploads check the type and the size. A code by e-mail can be asked for once a minute, and the answer doesn't tell whether the address has an account. The contact form takes five messages an hour from an address (per worker process, so limit it in front of the server too).
62
+ - A session lasts `ADMIN_SESSION_EXPIRE_DAYS` of `.env` (90 days without it): the token carries its sign-in time and the API checks it, so a copied token ends too. A new password ends all sessions of before.
63
+ - Writing routes are POST only and check the session. Uploads check the type and the size. A code by e-mail can be asked for once a minute and is good for 30 minutes (wrong tries don't make it last longer); the answers to asking for a code and to setting a new password don't tell whether the address has an account. The contact form takes five messages an hour from an address (per worker process, so limit it in front of the server too).
63
64
  - Requests from native apps have no `Origin` header, so the CSRF check of the API lets them through. It still checks browsers.
64
65
 
65
66
  ## Dropped from the web-only version
@@ -46,7 +46,7 @@ CREATE TABLE IF NOT EXISTS $__s_user (
46
46
  nickname VARCHAR(200) NOT NULL DEFAULT '',
47
47
  username VARCHAR(150) NOT NULL DEFAULT '',
48
48
  email VARCHAR(100) NOT NULL DEFAULT '',
49
- password VARCHAR(100) NOT NULL DEFAULT '',
49
+ password VARCHAR(255) NOT NULL DEFAULT '',
50
50
  usertype VARCHAR(25) NOT NULL DEFAULT '',
51
51
  block CHAR(1) NOT NULL DEFAULT '0',
52
52
  sendemail CHAR(1) DEFAULT '0',
@@ -57,7 +57,7 @@ CREATE TABLE IF NOT EXISTS $__s_user (
57
57
  registerdate VARCHAR(20) NOT NULL DEFAULT '',
58
58
  lastvisitdate VARCHAR(20) NOT NULL DEFAULT '',
59
59
  activated CHAR(1) NOT NULL DEFAULT '0',
60
- activation VARCHAR(10) NOT NULL DEFAULT '',
60
+ activation VARCHAR(40) NOT NULL DEFAULT '',
61
61
  points INTEGER NOT NULL DEFAULT 0,
62
62
  pwtips VARCHAR(100) DEFAULT '',
63
63
  pwretry INTEGER NOT NULL DEFAULT 0,
@@ -1,75 +1,101 @@
1
- #-- Auto Created By WebNoCoding at:2015-06-03 16:51:43
2
- #-- Never name a table with plural (such as "users")
3
- #-- Never name a table using a reserved keyword (such as "user")
4
- #-- Never prefix your table name with "tbl" or some other object type prefix
5
-
6
- CREATE TABLE $__s_page (
7
- pageid VARCHAR(50) NOT NULL,
8
- title VARCHAR(100) NOT NULL DEFAULT '',
9
- note VARCHAR(250) NOT NULL DEFAULT '',
10
- package VARCHAR(20) NOT NULL DEFAULT '',
11
- items TEXT NOT NULL DEFAULT '',
12
- updateduserid INTEGER,
13
- updatedstamp VARCHAR(20),
14
- PRIMARY KEY (pageid)
15
- );
16
-
17
- CREATE TABLE $__s_menu (
18
- menuid VARCHAR(50) NOT NULL,
19
- title VARCHAR(100) NOT NULL DEFAULT '',
20
- note VARCHAR(250) NOT NULL DEFAULT '',
21
- package VARCHAR(20) NOT NULL DEFAULT '',
22
- items TEXT NOT NULL DEFAULT '',
23
- updateduserid INTEGER,
24
- updatedstamp VARCHAR(20),
25
- PRIMARY KEY (menuid)
26
- );
27
-
28
- CREATE TABLE $__s_user (
29
- id INTEGER NOT NULL DEFAULT '0',
30
- gid INTEGER NOT NULL DEFAULT '1',
31
- level INTEGER NOT NULL DEFAULT '0',
32
- nickname VARCHAR(200) NOT NULL DEFAULT '',
33
- username VARCHAR(150) NOT NULL DEFAULT '',
34
- email VARCHAR(100) NOT NULL DEFAULT '',
35
- password VARCHAR(100) NOT NULL DEFAULT '',
36
- usertype VARCHAR(25) NOT NULL DEFAULT '',
37
- block CHAR(1) NOT NULL DEFAULT '0',
38
- sendemail CHAR(1) DEFAULT '0',
39
- gender VARCHAR(10) DEFAULT '0',
40
- age INTEGER NOT NULL DEFAULT '0',
41
- training INTEGER NOT NULL DEFAULT '0',
42
- preference VARCHAR(100) NOT NULL DEFAULT '',
43
- registerdate VARCHAR(20) NOT NULL DEFAULT '',
44
- lastvisitdate VARCHAR(20) NOT NULL DEFAULT '',
45
- activated CHAR(1) NOT NULL DEFAULT '0',
46
- activation VARCHAR(10) NOT NULL DEFAULT '',
47
- points INTEGER NOT NULL DEFAULT '0',
48
- pwtips VARCHAR(100) DEFAULT '',
49
- pwretry INTEGER NOT NULL DEFAULT '0',
50
- pwquestion VARCHAR(100) DEFAULT '',
51
- pwanswer VARCHAR(100) DEFAULT '',
52
- PRIMARY KEY (id)
53
- );
54
-
55
- #-- TABLE:$__st_calendar
56
- CREATE TABLE $__s_calendar (
57
- calendarid VARCHAR(50) NOT NULL,
58
- title VARCHAR(250) NOT NULL DEFAULT '',
59
- published CHAR(1) NOT NULL DEFAULT '0',
60
- remark VARCHAR(250),
61
- monthfrom VARCHAR(6),
62
- monthto VARCHAR(6),
63
- bkcolor VARCHAR(7),
64
- cidstring VARCHAR(50) NOT NULL DEFAULT '',
65
- PRIMARY KEY (calendarid)
66
- );
67
-
68
- CREATE TABLE $__s_user_right (
69
- username VARCHAR(150) NOT NULL,
70
- rightsid VARCHAR(50) NOT NULL,
71
- rightsgroup VARCHAR(10) NOT NULL DEFAULT '',
72
- value TEXT NOT NULL,
73
- PRIMARY KEY (username, rightsid)
74
- );
75
-
1
+ #-- Auto Created By WebNoCoding at:2015-06-03 16:51:43
2
+ #-- Never name a table with plural (such as "users")
3
+ #-- Never name a table using a reserved keyword (such as "user")
4
+ #-- Never prefix your table name with "tbl" or some other object type prefix
5
+ CREATE TABLE $__s_page (
6
+ pageid VARCHAR(50) NOT NULL,
7
+ name VARCHAR(100) NOT NULL DEFAULT '',
8
+ is_component INTEGER NOT NULL DEFAULT 0,
9
+ remark VARCHAR(250) NOT NULL DEFAULT '',
10
+ package VARCHAR(20) NOT NULL DEFAULT '',
11
+ accesslevel CHAR(1) NOT NULL DEFAULT '0',
12
+ json TEXT NOT NULL DEFAULT '',
13
+ updateduserid INTEGER,
14
+ updatetime INTEGER NOT NULL DEFAULT 0,
15
+ PRIMARY KEY (pageid)
16
+ );
17
+ CREATE TABLE $__s_menu (
18
+ menuid VARCHAR(50) NOT NULL,
19
+ name VARCHAR(100) NOT NULL DEFAULT '',
20
+ remark VARCHAR(250) NOT NULL DEFAULT '',
21
+ package VARCHAR(20) NOT NULL DEFAULT '',
22
+ accesslevel CHAR(1) NOT NULL DEFAULT '0',
23
+ json TEXT NOT NULL DEFAULT '',
24
+ updateduserid INTEGER,
25
+ updatetime INTEGER NOT NULL DEFAULT 0,
26
+ PRIMARY KEY (menuid)
27
+ );
28
+ CREATE TABLE $__s_process (
29
+ processid VARCHAR(50) NOT NULL,
30
+ name VARCHAR(100) NOT NULL DEFAULT '',
31
+ accesslevel CHAR(1) NOT NULL DEFAULT '0',
32
+ json TEXT NOT NULL DEFAULT '',
33
+ package VARCHAR(20) NOT NULL DEFAULT '',
34
+ remark VARCHAR(250) NOT NULL DEFAULT '',
35
+ updatetime INTEGER NOT NULL DEFAULT 0,
36
+ PRIMARY KEY (processid)
37
+ );
38
+ CREATE TABLE $__s_user (
39
+ id INTEGER NOT NULL DEFAULT '0',
40
+ gid INTEGER NOT NULL DEFAULT '1',
41
+ level INTEGER NOT NULL DEFAULT '0',
42
+ nickname VARCHAR(200) NOT NULL DEFAULT '',
43
+ username VARCHAR(150) NOT NULL DEFAULT '',
44
+ email VARCHAR(100) NOT NULL DEFAULT '',
45
+ password VARCHAR(255) NOT NULL DEFAULT '',
46
+ usertype VARCHAR(25) NOT NULL DEFAULT '',
47
+ block CHAR(1) NOT NULL DEFAULT '0',
48
+ sendemail CHAR(1) DEFAULT '0',
49
+ gender VARCHAR(10) DEFAULT '0',
50
+ age INTEGER NOT NULL DEFAULT '0',
51
+ training INTEGER NOT NULL DEFAULT '0',
52
+ preference VARCHAR(100) NOT NULL DEFAULT '',
53
+ registerdate VARCHAR(20) NOT NULL DEFAULT '',
54
+ lastvisitdate VARCHAR(20) NOT NULL DEFAULT '',
55
+ activated CHAR(1) NOT NULL DEFAULT '0',
56
+ activation VARCHAR(40) NOT NULL DEFAULT '',
57
+ points INTEGER NOT NULL DEFAULT '0',
58
+ pwtips VARCHAR(100) DEFAULT '',
59
+ pwretry INTEGER NOT NULL DEFAULT '0',
60
+ pwquestion VARCHAR(100) DEFAULT '',
61
+ pwanswer VARCHAR(100) DEFAULT '',
62
+ PRIMARY KEY (id)
63
+ );
64
+ #-- TABLE:$__st_calendar
65
+ CREATE TABLE $__s_calendar (
66
+ calendarid VARCHAR(50) NOT NULL,
67
+ title VARCHAR(250) NOT NULL DEFAULT '',
68
+ published CHAR(1) NOT NULL DEFAULT '0',
69
+ remark VARCHAR(250),
70
+ monthfrom VARCHAR(6),
71
+ monthto VARCHAR(6),
72
+ bkcolor VARCHAR(7),
73
+ cidstring VARCHAR(50) NOT NULL DEFAULT '',
74
+ PRIMARY KEY (calendarid)
75
+ );
76
+ CREATE TABLE $__s_user_right (
77
+ username VARCHAR(150) NOT NULL,
78
+ rightsid VARCHAR(50) NOT NULL,
79
+ rightsgroup VARCHAR(10) NOT NULL DEFAULT '',
80
+ value TEXT NOT NULL,
81
+ PRIMARY KEY (username, rightsid)
82
+ );
83
+
84
+ CREATE TABLE $__image_folder (
85
+ id INTEGER NOT NULL DEFAULT '0',
86
+ folder_id VARCHAR(10) NOT NULL DEFAULT '',
87
+ display_name VARCHAR(50) NOT NULL DEFAULT '',
88
+ parent_full_path VARCHAR(255) NOT NULL DEFAULT '',
89
+ full_path VARCHAR(255) NOT NULL DEFAULT '',
90
+ PRIMARY KEY (id)
91
+ );
92
+ #-- file_id has extension name
93
+ CREATE TABLE $__image (
94
+ id INTEGER NOT NULL DEFAULT '0',
95
+ file_id VARCHAR(20) NOT NULL DEFAULT '',
96
+ display_name VARCHAR(50) NOT NULL DEFAULT '',
97
+ parent_full_path VARCHAR(255) NOT NULL DEFAULT '',
98
+ version INTEGER NOT NULL DEFAULT '0',
99
+ updatetime INTEGER NOT NULL DEFAULT '0',
100
+ PRIMARY KEY (id)
101
+ );
@@ -1,5 +1,5 @@
1
1
  import { ServerResponse } from 'http';
2
- import { Logger, ServerRequest, ApiHelper } from 'lupine.api';
2
+ import { Logger, ServerRequest, ApiHelper, getClientIp } from 'lupine.api';
3
3
  import { sendSiteEmail } from './send-email';
4
4
 
5
5
  const logger = new Logger('qa');
@@ -11,7 +11,7 @@ const MAX_PER_HOUR = 5;
11
11
  const oneLine = (s: unknown, max: number) => String(s).replace(/[\r\n]+/g, ' ').trim().slice(0, max);
12
12
 
13
13
  export const addContact = async (req: ServerRequest, res: ServerResponse) => {
14
- const ip = String(req.socket.remoteAddress || '');
14
+ const ip = getClientIp(req);
15
15
  const now = Date.now();
16
16
  const recent = (sent.get(ip) || []).filter((t) => now - t < 3600 * 1000);
17
17
  if (recent.length >= MAX_PER_HOUR) {
@@ -19,11 +19,30 @@ import {
19
19
  DEV_ADMIN_USER_KEY_NAME,
20
20
  DEV_ADMIN_PASS_KEY_NAME,
21
21
  DEV_ADMIN_SESSION_INVALID_BEFORE_KEY_NAME,
22
+ loginGuard,
23
+ getClientIp,
22
24
  } from 'lupine.api';
23
25
  import { sendEmail, sendSiteEmail } from './send-email';
24
26
 
25
27
  const PW_RETRY_MAX = 5;
26
28
  const PW_RETRY_RESET_MINUTES = 15;
29
+
30
+ // A code by email (to sign in or set a new password) is good for CODE_MINUTES from when it was sent. The time is kept
31
+ // with it, as "code.time" in activation: lastvisitdate moves with every wrong try, so it can't tell the age of a code
32
+ const CODE_MINUTES = 30;
33
+ const codeIssuedAt = (stored: unknown): number => Number(String(stored || '').split('.')[1]) || 0;
34
+ const codeMatches = (stored: unknown, provided: unknown): boolean => {
35
+ const code = String(stored || '').split('.')[0];
36
+ const issued = codeIssuedAt(stored);
37
+ return (
38
+ code.length >= 6 &&
39
+ issued > 0 &&
40
+ Date.now() - issued <= CODE_MINUTES * 60 * 1000 &&
41
+ CryptoUtils.timingSafeEqual(code, String(provided || ''))
42
+ );
43
+ };
44
+ // a user's session: the cookie and the login time in the token (which the server checks) end after these days
45
+ const userSessionDays = () => getSessionExpireDays(ADMIN_SESSION_EXPIRE_DAYS_KEY_NAME, 90);
27
46
  const logger = new Logger('user-api');
28
47
 
29
48
  export type LoginJsonProps = {
@@ -122,7 +141,7 @@ export const appAdminHookCheckLogin: AppAdminHookCheckLoginProps = async (
122
141
  const adminPass = process.env['ADMIN_PASS'] || '';
123
142
  const pwCheck =
124
143
  username && password && password.length <= 256 && adminUser && adminPass
125
- ? CryptoUtils.verifyPasswordLayered(password, adminPass)
144
+ ? await CryptoUtils.verifyPasswordLayeredAsync(password, adminPass)
126
145
  : { valid: false as const };
127
146
  if (
128
147
  adminUser &&
@@ -154,12 +173,12 @@ const computeUserSessionHash = (username: string, storedPassword: string): strin
154
173
  return CryptoUtils.hash(`${username}:${storedPassword}`);
155
174
  };
156
175
 
157
- const verifyUserPassword = (plainPassword: string, storedPassword: string): boolean => {
176
+ const verifyUserPassword = async (plainPassword: string, storedPassword: string): Promise<boolean> => {
158
177
  if (!plainPassword || plainPassword.length > 256 || !storedPassword) {
159
178
  return false;
160
179
  }
161
180
  if (storedPassword.startsWith('scrypt$')) {
162
- return CryptoUtils.verifyPassword(plainPassword, storedPassword);
181
+ return await CryptoUtils.verifyPasswordAsync(plainPassword, storedPassword);
163
182
  }
164
183
  return CryptoUtils.timingSafeEqual(CryptoUtils.hash(plainPassword), storedPassword);
165
184
  };
@@ -229,6 +248,14 @@ export const getUserFromCookie = async (
229
248
  }
230
249
  }
231
250
 
251
+ // a user's token carries its login time: an old (or copied) token ends like the cookie does
252
+ if (isSessionExpired(json.l, userSessionDays())) {
253
+ if (sendResponseWhenError) {
254
+ ApiHelper.sendJson(req, res, { status: 'error', message: langHelper.getLang('shared:not_logged_in') });
255
+ }
256
+ return false;
257
+ }
258
+
232
259
  // verify whether the user is blocked
233
260
  const db = apiCache.getDb();
234
261
  const record = await db.selectObject('$__s_user', ['*'], {
@@ -409,19 +436,25 @@ export const userLogin = async (req: ServerRequest, res: ServerResponse) => {
409
436
  return true;
410
437
  }
411
438
 
439
+ // ADMIN_USER of .env: failed tries are counted per client address (loginGuard), and the password is only checked
440
+ // (scrypt) for this user name
412
441
  const adminUser = process.env['ADMIN_USER'] || '';
413
442
  const adminPass = process.env['ADMIN_PASS'] || '';
443
+ const isAdminName = !!adminUser && !!adminPass && typeof data.u === 'string' && adminApiHelper.timingSafeEqual(data.u, adminUser);
444
+ if (isAdminName && (await loginGuard.isLocked(req))) return loginGuard.sendLocked(req, res);
414
445
  const adminPwCheck =
415
- typeof data.u === 'string' &&
416
- typeof data.p === 'string' &&
417
- data.p.length <= 256 &&
418
- adminUser &&
419
- adminPass
420
- ? CryptoUtils.verifyPasswordLayered(data.p, adminPass)
446
+ isAdminName && typeof data.p === 'string' && data.p.length <= 256
447
+ ? await CryptoUtils.verifyPasswordLayeredAsync(data.p, adminPass)
421
448
  : { valid: false as const };
422
- if (adminUser && adminApiHelper.timingSafeEqual(String(data.u || ''), adminUser) && adminPwCheck.valid && adminPwCheck.keyHex) {
449
+ if (isAdminName && (!adminPwCheck.valid || !adminPwCheck.keyHex)) {
450
+ await loginGuard.fail(req);
451
+ ApiHelper.sendJson(req, res, { status: 'error', message: langHelper.getLang('shared:login_failed') });
452
+ return true;
453
+ }
454
+ if (isAdminName && adminPwCheck.keyHex) {
455
+ loginGuard.clear(req);
423
456
  const loginJson: LoginJsonProps = {
424
- ip: req.socket.remoteAddress as string,
457
+ ip: getClientIp(req),
425
458
  id: 0,
426
459
  u: data.u as string,
427
460
  t: 'admin',
@@ -521,9 +554,7 @@ export const userLogin = async (req: ServerRequest, res: ServerResponse) => {
521
554
  if (await checkRetryLockout()) {
522
555
  return true;
523
556
  }
524
- const providedCode = String(data.c || '');
525
- const storedCode = String(result[0].activation || '');
526
- if (storedCode.length < 6 || !CryptoUtils.timingSafeEqual(storedCode, providedCode)) {
557
+ if (!codeMatches(result[0].activation, data.c)) {
527
558
  await recordUserRetry();
528
559
  const response = {
529
560
  status: 'error',
@@ -537,11 +568,7 @@ export const userLogin = async (req: ServerRequest, res: ServerResponse) => {
537
568
  if (await checkRetryLockout()) {
538
569
  return true;
539
570
  }
540
- const providedCode = String(data.c || '');
541
- const storedCode = String(result[0].activation || '');
542
- const codeIssuedAt = DateUtils.fromJSONString(result[0].lastvisitdate);
543
- const isCodeExpired = !codeIssuedAt || Date.now() - codeIssuedAt.getTime() > 30 * 60 * 1000;
544
- if (storedCode.length < 6 || isCodeExpired || !CryptoUtils.timingSafeEqual(storedCode, providedCode)) {
571
+ if (!codeMatches(result[0].activation, data.c)) {
545
572
  await recordUserRetry();
546
573
  const response = {
547
574
  status: 'error',
@@ -558,7 +585,7 @@ export const userLogin = async (req: ServerRequest, res: ServerResponse) => {
558
585
  return true;
559
586
  }
560
587
 
561
- if (!loginOk && !verifyUserPassword(String(data.p || ''), String(result[0].password || ''))) {
588
+ if (!loginOk && !(await verifyUserPassword(String(data.p || ''), String(result[0].password || '')))) {
562
589
  await recordUserRetry();
563
590
  const response = {
564
591
  status: 'error',
@@ -576,18 +603,19 @@ export const userLogin = async (req: ServerRequest, res: ServerResponse) => {
576
603
  lastvisitdate: DateUtils.toJSONString(new Date()),
577
604
  };
578
605
  if (!loginOk && typeof data.p === 'string' && activePasswordHash && !activePasswordHash.startsWith('scrypt$')) {
579
- activePasswordHash = CryptoUtils.hashPassword(data.p);
606
+ activePasswordHash = await CryptoUtils.hashPasswordAsync(data.p);
580
607
  updateLoginObj.password = activePasswordHash;
581
608
  }
582
609
 
583
610
  await db.updateObject('$__s_user', updateLoginObj, { username: data.u as string });
584
611
  const nameAndPassHash = CryptoUtils.sha256(`${result[0].username}:${activePasswordHash}`);
585
612
  const loginJson: LoginJsonProps = {
586
- ip: req.socket.remoteAddress as string,
613
+ ip: getClientIp(req),
587
614
  id: result[0].id,
588
615
  u: result[0].username,
589
616
  t: result[0].usertype,
590
617
  h: nameAndPassHash,
618
+ l: Date.now(),
591
619
  };
592
620
 
593
621
  const token = JSON.stringify(loginJson);
@@ -604,7 +632,7 @@ export const userLogin = async (req: ServerRequest, res: ServerResponse) => {
604
632
  },
605
633
  };
606
634
  req.locals.setCookie('_token', tokenCookie, {
607
- expireDays: getSessionExpireDays(ADMIN_SESSION_EXPIRE_DAYS_KEY_NAME, 90),
635
+ expireDays: userSessionDays(),
608
636
  path: '/',
609
637
  httpOnly: true,
610
638
  secure: isHttpsRequest(req),
@@ -702,7 +730,7 @@ export const userReg = async (req: ServerRequest, res: ServerResponse) => {
702
730
  nickname: data.preferredName as string,
703
731
  username: data.u as string,
704
732
  email: data.u as string,
705
- password: CryptoUtils.hashPassword(data.p),
733
+ password: await CryptoUtils.hashPasswordAsync(data.p),
706
734
  gender: data.sex as string,
707
735
  usertype: 'user',
708
736
  registerdate: lastvisitdate,
@@ -779,7 +807,7 @@ export const userResetCode = async (req: ServerRequest, res: ServerResponse) =>
779
807
  }
780
808
 
781
809
  const db = apiCache.getDb();
782
- const result = await db.selectObject('$__s_user', ['id', 'activation', 'lastvisitdate'], {
810
+ const result = await db.selectObject('$__s_user', ['id', 'activation'], {
783
811
  username: userEmail,
784
812
  });
785
813
  // the same answer whether the address is known or not: nobody learns who has an account here
@@ -789,15 +817,13 @@ export const userResetCode = async (req: ServerRequest, res: ServerResponse) =>
789
817
  return true;
790
818
  }
791
819
  // one code a minute: the form can't be used to flood a mailbox
792
- const issued = result[0].activation && DateUtils.fromJSONString(result[0].lastvisitdate);
793
- if (issued && Date.now() - issued.getTime() < 60 * 1000) {
820
+ if (Date.now() - codeIssuedAt(result[0].activation) < 60 * 1000) {
794
821
  answer();
795
822
  return true;
796
823
  }
797
824
 
798
- const lastvisitdate = DateUtils.toJSONString(new Date());
799
825
  const random = CryptoUtils.randomNumberString(8);
800
- await db.updateObject('$__s_user', { activation: random, lastvisitdate: lastvisitdate }, { username: userEmail });
826
+ await db.updateObject('$__s_user', { activation: `${random}.${Date.now()}` }, { username: userEmail });
801
827
 
802
828
  const siteUrl = (await apiStorage.getWeb('siteUrl')) || 'https://your-site.com';
803
829
  const emailTitle = 'Authentication code';
@@ -829,12 +855,9 @@ export const userResetPw = async (req: ServerRequest, res: ServerResponse) => {
829
855
  const result = await db.selectObject('$__s_user', ['id', 'activation', 'pwretry', 'lastvisitdate'], {
830
856
  username: userEmail,
831
857
  });
858
+ // the answer of a wrong code: nobody learns here who has an account
832
859
  if (!result || result.length !== 1) {
833
- const response = {
834
- status: 'error',
835
- message: langHelper.getLang('shared:user_not_found'),
836
- };
837
- ApiHelper.sendJson(req, res, response);
860
+ ApiHelper.sendJson(req, res, { status: 'error', message: langHelper.getLang('shared:wrong_activation') });
838
861
  return true;
839
862
  }
840
863
 
@@ -852,10 +875,7 @@ export const userResetPw = async (req: ServerRequest, res: ServerResponse) => {
852
875
  }
853
876
  }
854
877
 
855
- const storedCode = String(result[0].activation || '');
856
- const codeIssuedAt = DateUtils.fromJSONString(result[0].lastvisitdate);
857
- const isCodeExpired = !codeIssuedAt || Date.now() - codeIssuedAt.getTime() > 30 * 60 * 1000;
858
- if (storedCode.length < 6 || isCodeExpired || !CryptoUtils.timingSafeEqual(storedCode, String(activation))) {
878
+ if (!codeMatches(result[0].activation, activation)) {
859
879
  await db.updateObject(
860
880
  '$__s_user',
861
881
  { pwretry: (Number(result[0].pwretry) || 0) + 1, lastvisitdate: DateUtils.toJSONString(new Date()) },
@@ -870,7 +890,7 @@ export const userResetPw = async (req: ServerRequest, res: ServerResponse) => {
870
890
  }
871
891
  await db.updateObject(
872
892
  '$__s_user',
873
- { activation: '', pwretry: 0, password: CryptoUtils.hashPassword(pass) },
893
+ { activation: '', activated: '1', pwretry: 0, password: await CryptoUtils.hashPasswordAsync(pass) },
874
894
  { username: userEmail }
875
895
  );
876
896
  const response = {
@@ -908,7 +928,7 @@ export const updateUser = async (req: ServerRequest, res: ServerResponse) => {
908
928
 
909
929
  const updateObj: any = { usertype: usertype };
910
930
  if (password) {
911
- updateObj['password'] = CryptoUtils.hashPassword(password);
931
+ updateObj['password'] = await CryptoUtils.hashPasswordAsync(password);
912
932
  }
913
933
  // clear activation, only admin can update
914
934
  updateObj['activation'] = '';
@@ -967,7 +987,7 @@ export const updateProfile = async (req: ServerRequest, res: ServerResponse) =>
967
987
  ApiHelper.sendJson(req, res, response);
968
988
  return true;
969
989
  }
970
- updateObj['password'] = CryptoUtils.hashPassword(password);
990
+ updateObj['password'] = await CryptoUtils.hashPasswordAsync(password);
971
991
  }
972
992
  const result = await db.updateObject('$__s_user', updateObj, {
973
993
  id: loginJson.id,
@@ -39,6 +39,15 @@ export const setServerAddress = (address: string) => {
39
39
  base = address.replace(/\/+$/, '');
40
40
  };
41
41
 
42
+ // the copy for GitHub Pages (web/src/lupine-template-fullstack-starter): the app without a server, every call answers
43
+ // that (the app shows the message)
44
+ let noServer = false;
45
+ /** no server: what needs the API says that this is a static page */
46
+ export const setNoServer = () => {
47
+ noServer = true;
48
+ };
49
+ export const noServerText = () => t('api.noServer', 'This is only a static page, without a back-end server: accounts and favourites work in a project made from this template');
50
+
42
51
  // a native app only: the token of the session, and the user, so that the app knows it at once and offline
43
52
  const TOKEN = 'session';
44
53
  const USER = 'user';
@@ -63,6 +72,7 @@ const forget = () => {
63
72
  };
64
73
 
65
74
  const call = async (path: string, body?: object): Promise<Answer> => {
75
+ if (noServer) return { status: 'error', message: noServerText() };
66
76
  const headers: { [name: string]: string } = { Accept: 'application/json' };
67
77
  if (body) headers['Content-Type'] = 'application/json';
68
78
  if (native) {
@@ -69,7 +69,7 @@ addTexts('zh-CN', {
69
69
  version: '版本',
70
70
  },
71
71
  about: { tagline: '应用在所有平台上,管理页面在网站上,共用一个 API', text: '使用 lupine.native(应用)、lupine.web(管理页面)和 lupine.api(服务器)构建。' },
72
- api: { offline: '无法连接服务器', badAnswer: '服务器的回答无法识别({status})', failed: '出错了', done: '完成' },
72
+ api: { noServer: '这只是静态网页,没有后端服务器:用这个模板创建项目后,就能使用账号和收藏', offline: '无法连接服务器', badAnswer: '服务器的回答无法识别({status})', failed: '出错了', done: '完成' },
73
73
  });
74
74
  // and those of the controls
75
75
  addLnTexts({ 'zh-Hans': lnZhHans });
@@ -13,6 +13,11 @@
13
13
  "html": "web/src/admin/index.html",
14
14
  "outdir": "/admin",
15
15
  "env": "web"
16
+ },
17
+ {
18
+ "index": "web/src/lupine-template-fullstack-starter/index.tsx",
19
+ "html": "web/src/lupine-template-fullstack-starter/index.html",
20
+ "outdir": "/lupine-template-fullstack-starter"
16
21
  }
17
22
  ],
18
23
  "apiEntryPoint": "api/src/index.ts",
@@ -26,6 +31,16 @@
26
31
  "env": "all",
27
32
  "from": "api/resources",
28
33
  "to": "data/resources"
34
+ },
35
+ {
36
+ "env": "all",
37
+ "from": "web/src/lupine-template-fullstack-starter/assets",
38
+ "to": "web/lupine-template-fullstack-starter/assets"
39
+ },
40
+ {
41
+ "env": "all",
42
+ "from": "web/src/lupine-template-fullstack-starter/404.html",
43
+ "to": "web/lupine-template-fullstack-starter/404.html"
29
44
  }
30
45
  ]
31
46
  }
@@ -0,0 +1,35 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
+ <title>Page Not Found</title>
7
+ <style>
8
+ main {
9
+ display: flex;
10
+ height: 100vh;
11
+ justify-content: center;
12
+ align-items: center;
13
+ flex-direction: column;
14
+ }
15
+ .header404 {
16
+ font-size: 48px;
17
+ }
18
+ </style>
19
+ <script type="text/javascript">
20
+ // Single Page Apps for GitHub Pages, change all "/lupine-template-fullstack-starter/" to your github project name
21
+ if (window.location.pathname.includes('/lupine-template-fullstack-starter/')) {
22
+ window.location.href = '/lupine-template-fullstack-starter/?redirect=' + window.location.pathname;
23
+ }
24
+ </script>
25
+ </head>
26
+ <body>
27
+ <main>
28
+ <h4 class="header404">404</h4>
29
+ <div class="content-404">Uh-oh! We couldn't find the page you are looking for.</div>
30
+ <p>
31
+ <a href="/lupine-template-fullstack-starter/">Check our home page</a>
32
+ </p>
33
+ </main>
34
+ </body>
35
+ </html>
@@ -0,0 +1,39 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <title>Lupine Template Fullstack Starter</title>
6
+ <meta name="description" content="Lupine Template Fullstack Starter - an app with accounts for iOS, Android, macOS, Windows and the web, its API with a database, and an admin site. This page is static, without the server. Powered by Lupine.js." />
7
+
8
+ <!-- Open Graph / Facebook -->
9
+ <meta property="og:type" content="website" />
10
+ <meta property="og:url" content="https://uuware.github.io/lupine-template-fullstack-starter/" />
11
+ <meta property="og:title" content="Lupine Template Fullstack Starter (Powered by Lupine.js)" />
12
+ <meta property="og:description" content="Lupine Template Fullstack Starter - an app with accounts for iOS, Android, macOS, Windows and the web, its API with a database, and an admin site. This page is static, without the server. Powered by Lupine.js." />
13
+ <meta property="og:image" content="https://uuware.github.io/lupine-template-fullstack-starter/assets/og-image.png" />
14
+
15
+ <!-- Twitter -->
16
+ <meta property="twitter:card" content="summary_large_image" />
17
+ <meta property="twitter:url" content="https://uuware.github.io/lupine-template-fullstack-starter/" />
18
+ <meta property="twitter:title" content="Lupine Template Fullstack Starter (Powered by Lupine.js)" />
19
+ <meta property="twitter:description" content="Lupine Template Fullstack Starter - an app with accounts for iOS, Android, macOS, Windows and the web, its API with a database, and an admin site. This page is static, without the server. Powered by Lupine.js." />
20
+ <meta property="twitter:image" content="https://uuware.github.io/lupine-template-fullstack-starter/assets/og-image.png" />
21
+
22
+ <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" />
23
+ <!--META-ENV-START-->
24
+ <!--META-ENV-END-->
25
+ <link rel="shortcut icon" href="{SUBDIR}/assets/favicon.ico?t={hash}" type="image/x-icon" />
26
+ <style>
27
+ html,
28
+ body,
29
+ .lupine-root {
30
+ height: 100%;
31
+ margin: 0;
32
+ }
33
+ </style>
34
+ <script defer src="{SUBDIR}/index.js?t={hash}"></script>
35
+ </head>
36
+ <body>
37
+ <div class="lupine-root"></div>
38
+ </body>
39
+ </html>
@@ -0,0 +1,17 @@
1
+ // lupine.native.core/web first: the storage of the browser, which the controls read when they start
2
+ import { runApp } from 'lupine.native.core/web';
3
+ import { router, Toast } from 'lupine.native.components';
4
+ import { App } from '../../../app/src/app';
5
+ import { noServerText, setNoServer } from '../../../app/src/shell/api';
6
+
7
+ // The copy for GitHub Pages (https://uuware.github.io/lupine-template-fullstack-starter/): the app alone, a static page
8
+ // without the server, so what needs the API only says that (setNoServer); the admin pages are not in it. The address
9
+ // bar follows its pages under the folder of the project; 404.html sends an address that GitHub doesn't have back to
10
+ // this page (?redirect=), and the router opens it. The server of the site only loads this file, so the app starts in
11
+ // the browser.
12
+ if (typeof document === 'object') {
13
+ setNoServer();
14
+ router.followUrl({ paths: true, base: '/lupine-template-fullstack-starter' });
15
+ runApp(App, document.querySelector('.lupine-root') as HTMLElement);
16
+ setTimeout(() => Toast.info(noServerText(), 6000), 800);
17
+ }