diff --git a/.gitignore b/.gitignore index 5b5cd12..f18f616 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,6 @@ node_modules dist yarn-error.log + +src/package.json +config/local.* diff --git a/package.json b/package.json index 75ef1c9..850af94 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "swaf", - "version": "0.23.0", + "version": "0.23.1", "description": "Structure Web Application Framework.", "repository": "https://eternae.ink/arisu/swaf", "author": "Alice Gaudon ", @@ -10,16 +10,17 @@ "registry": "https://registry.npmjs.com", "access": "public" }, - "main": "dist/src/main.js", + "main": "dist/main.js", "types": "dist/index.d.ts", "scripts": { "test": "jest --verbose --runInBand", "clean": "(test ! -d dist || rm -r dist)", + "prepare": "cp package.json src/", "compile": "yarn clean && tsc", - "dev": "concurrently -k -n \"Typescript,Node,Webpack,Maildev\" -p \"[{name}]\" -c \"blue,green,red,yellow\" \"tsc --watch\" \"nodemon\" \"maildev\"", - "build": "yarn compile && cp -r package.json yarn.lock README.md config/ views/ dist/ && mkdir dist/types && cp src/types/* dist/types/", + "dev": "yarn prepare && concurrently -k -n \"Typescript,Node,Webpack,Maildev\" -p \"[{name}]\" -c \"blue,green,red,yellow\" \"tsc --watch\" \"nodemon\" \"maildev\"", + "build": "yarn prepare && yarn compile && cp -r yarn.lock README.md config/ views/ dist/ && mkdir dist/types && cp src/types/* dist/types/", "lint": "eslint . --ext .js,.jsx,.ts,.tsx", - "release": "yarn lint && yarn test && yarn build && cd dist && yarn publish" + "release": "yarn build && yarn lint && yarn test && cd dist && yarn publish" }, "devDependencies": { "@types/compression": "^1.7.0", diff --git a/src/TestApp.ts b/src/TestApp.ts index de24b16..ee5253c 100644 --- a/src/TestApp.ts +++ b/src/TestApp.ts @@ -1,18 +1,18 @@ -import Application from "../src/Application"; -import Migration, {MigrationType} from "../src/db/Migration"; -import ExpressAppComponent from "../src/components/ExpressAppComponent"; -import RedisComponent from "../src/components/RedisComponent"; -import MysqlComponent from "../src/components/MysqlComponent"; -import NunjucksComponent from "../src/components/NunjucksComponent"; -import LogRequestsComponent from "../src/components/LogRequestsComponent"; -import MailComponent from "../src/components/MailComponent"; -import SessionComponent from "../src/components/SessionComponent"; -import AuthComponent from "../src/auth/AuthComponent"; -import FormHelperComponent from "../src/components/FormHelperComponent"; -import ServeStaticDirectoryComponent from "../src/components/ServeStaticDirectoryComponent"; +import Application from "./Application"; +import Migration, {MigrationType} from "./db/Migration"; +import ExpressAppComponent from "./components/ExpressAppComponent"; +import RedisComponent from "./components/RedisComponent"; +import MysqlComponent from "./components/MysqlComponent"; +import NunjucksComponent from "./components/NunjucksComponent"; +import LogRequestsComponent from "./components/LogRequestsComponent"; +import MailComponent from "./components/MailComponent"; +import SessionComponent from "./components/SessionComponent"; +import AuthComponent from "./auth/AuthComponent"; +import FormHelperComponent from "./components/FormHelperComponent"; +import ServeStaticDirectoryComponent from "./components/ServeStaticDirectoryComponent"; import {Express} from "express"; -import MagicLinkAuthMethod from "../src/auth/magic_link/MagicLinkAuthMethod"; -import PasswordAuthMethod from "../src/auth/password/PasswordAuthMethod"; +import MagicLinkAuthMethod from "./auth/magic_link/MagicLinkAuthMethod"; +import PasswordAuthMethod from "./auth/password/PasswordAuthMethod"; import {MAGIC_LINK_MAIL} from "./Mails"; import CreateMigrationsTable from "./migrations/CreateMigrationsTable"; import CreateUsersAndUserEmailsTableMigration from "./auth/migrations/CreateUsersAndUserEmailsTableMigration"; @@ -29,7 +29,7 @@ import Controller from "./Controller"; import AccountController from "./auth/AccountController"; import MakeMagicLinksSessionNotUniqueMigration from "./auth/magic_link/MakeMagicLinksSessionNotUniqueMigration"; import AddUsedToMagicLinksMigration from "./auth/magic_link/AddUsedToMagicLinksMigration"; -import packageJson = require('../package.json'); +import packageJson = require('./package.json'); import PreviousUrlComponent from "./components/PreviousUrlComponent"; export const MIGRATIONS = [ diff --git a/src/auth/magic_link/MagicLinkController.ts b/src/auth/magic_link/MagicLinkController.ts index 3df778c..e10163f 100644 --- a/src/auth/magic_link/MagicLinkController.ts +++ b/src/auth/magic_link/MagicLinkController.ts @@ -191,7 +191,8 @@ export default class MagicLinkController extends Controll if (!res.headersSent && user) { // Auth success - req.flash('success', `Authentication success. Welcome, ${user.name}!`); + const name = user.asOptional(UserNameComponent)?.name; + req.flash('success', `Authentication success. Welcome${name ? `, ${name}` : ''}`); res.redirect(req.getIntendedUrl() || Controller.route('home')); } break; diff --git a/src/helpers/BackendController.ts b/src/helpers/BackendController.ts index 66fc1c0..71a4d83 100644 --- a/src/helpers/BackendController.ts +++ b/src/helpers/BackendController.ts @@ -9,6 +9,8 @@ import UserEmail from "../auth/models/UserEmail"; import UserApprovedComponent from "../auth/models/UserApprovedComponent"; import {RequireAdminMiddleware, RequireAuthMiddleware} from "../auth/AuthComponent"; import NunjucksComponent from "../components/NunjucksComponent"; +import ModelFactory from "../db/ModelFactory"; +import UserNameComponent from "../auth/models/UserNameComponent"; export default class BackendController extends Controller { private static readonly menu: BackendMenuElement[] = []; @@ -65,6 +67,7 @@ export default class BackendController extends Controller { .get(); res.render('backend/accounts_approval', { accounts: accounts, + has_user_name_component: ModelFactory.get(User).hasComponent(UserNameComponent), }); } diff --git a/src/main.ts b/src/main.ts index 0ea8124..640f431 100644 --- a/src/main.ts +++ b/src/main.ts @@ -2,9 +2,9 @@ import {delimiter} from "path"; // Load config from specified path or default + swaf/config (default defaults) process.env['NODE_CONFIG_DIR'] = - __dirname + '/../../node_modules/swaf/config/' + __dirname + '/../node_modules/swaf/config/' + delimiter - + (process.env['NODE_CONFIG_DIR'] || __dirname + '/../../config/'); + + (process.env['NODE_CONFIG_DIR'] || __dirname + '/../config/'); import {logger} from "./Logger"; import TestApp from "./TestApp"; diff --git a/test/views/layouts/base.njk b/test/views/layouts/base.njk index a3b9693..a38ea56 100644 --- a/test/views/layouts/base.njk +++ b/test/views/layouts/base.njk @@ -23,7 +23,7 @@
  • - {{ user.name }} + {{ user.name | default('Account') }}
  • diff --git a/tsconfig.json b/tsconfig.json index f34d0e9..867a3b0 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,10 +11,7 @@ "moduleResolution": "Node", "esModuleInterop": true, "baseUrl": "dist", - "rootDirs": [ - "src", - "config" - ], + "rootDir": "src", "sourceRoot": "src", "inlineSourceMap": true, "inlineSources": true, diff --git a/views/backend/accounts_approval.njk b/views/backend/accounts_approval.njk index cc0ae9f..961ce5b 100644 --- a/views/backend/accounts_approval.njk +++ b/views/backend/accounts_approval.njk @@ -10,7 +10,9 @@ # + {% if has_user_name_component %} Name + {% endif %} Main email Registered at Action @@ -20,7 +22,9 @@ {% for user in accounts %} {{ user.id }} + {% if has_user_name_component %} {{ user.name }} + {% endif %} {{ user.mainEmail.getOrFail().email | default('No email') }} {{ user.created_at.toISOString() }}