合入主线登录和营业时段策略,对齐旧界面与 React 访问流程
This commit is contained in:
commit
42395de23a
113 files changed
+1915
-558
No files matched your search
@@ -6,8 +6,8 @@ const ShopSettings = require('../../domains/team/shop-settings');
|
||||
const { today, fail } = require('../../core/ledger');
|
||||
const { sha, derive } = require('../hash');
|
||||
const { createUser, ensureTeamAccounts } = require('../accounts');
|
||||
const { readBody } = require('../middleware/body');
|
||||
const { sessionToken } = require('../middleware/session');
|
||||
const { checkAccount, requireBusinessHours } = require('../middleware/shop-access');
|
||||
const { sessionToken, sessionInfo } = require('../middleware/session');
|
||||
const { ANONYMOUS, securityAudit } = require('../security-audit');
|
||||
|
||||
const who = u => ({ id: u.id, name: u.name, role: u.role });
|
||||
@@ -17,28 +17,28 @@ module.exports = [
|
||||
method: 'GET',
|
||||
path: '/api/session',
|
||||
auth: 'public',
|
||||
handler: ({ req, app, rawLedger: ledger }) => ({
|
||||
user: app.user(req),
|
||||
setup: !ledger.one('SELECT id FROM users LIMIT 1'),
|
||||
mode: app.mode,
|
||||
today: today(),
|
||||
brand: {
|
||||
storeName: ledger.one('SELECT id FROM users LIMIT 1') ? ShopSettings.read(ledger).storeName : '店铺台账',
|
||||
},
|
||||
loginOptions: ShopSettings.loginOptions(ledger)
|
||||
.filter(row => ledger.one('SELECT user_id FROM team_user_members WHERE member=?', row.member))
|
||||
.map(({ member, label }) => ({ member, label })),
|
||||
}),
|
||||
handler: ({ req, app, rawLedger: ledger, access }) => {
|
||||
const account = app.user(req);
|
||||
if (account) checkAccount(account, access);
|
||||
return sessionInfo(ledger, app.mode, account, access);
|
||||
},
|
||||
},
|
||||
{
|
||||
method: 'GET',
|
||||
path: '/api/access-window',
|
||||
auth: 'session',
|
||||
handler: ({ actor, access }) => ({ window: actor.role === 'owner' ? null : access.period }),
|
||||
},
|
||||
{
|
||||
method: 'POST',
|
||||
path: '/api/setup',
|
||||
auth: 'public',
|
||||
direct: true,
|
||||
handler: async ({ req, res, app, rawLedger: ledger }) => {
|
||||
handler: async ({ req, res, app, rawLedger: ledger, access, readBody }) => {
|
||||
requireBusinessHours(null, access.period);
|
||||
if (app.production || app.mode === 'demo' || ledger.one('SELECT id FROM users LIMIT 1'))
|
||||
fail('初始化入口已关闭', 403);
|
||||
const b = await readBody(req);
|
||||
const b = await readBody();
|
||||
if (b.storeName !== undefined) {
|
||||
const actor = require('../../core/new-shop').initialize(ledger, b, createUser);
|
||||
const result = app.session(res, actor);
|
||||
@@ -72,8 +72,8 @@ module.exports = [
|
||||
path: '/api/login',
|
||||
auth: 'public',
|
||||
direct: true,
|
||||
handler: async ({ req, res, app, rawLedger: ledger }) => {
|
||||
const b = await readBody(req);
|
||||
handler: async ({ req, res, app, rawLedger: ledger, access, readBody }) => {
|
||||
const b = await readBody();
|
||||
const u =
|
||||
b.member !== undefined
|
||||
? typeof b.member === 'string'
|
||||
@@ -101,6 +101,7 @@ module.exports = [
|
||||
});
|
||||
fail('账号或密码不正确', 401);
|
||||
}
|
||||
checkAccount(u, { outside: access.outside, period: app.access.currentWindow() });
|
||||
const result = app.session(res, u);
|
||||
securityAudit(ledger, req, 'auth:' + u.id, '登录成功', who(u));
|
||||
return result;
|
||||
@@ -113,14 +114,15 @@ module.exports = [
|
||||
auth: 'public',
|
||||
when: app => app.mode === 'demo',
|
||||
direct: true,
|
||||
handler: async ({ req, res, app, rawLedger: ledger }) => {
|
||||
const b = await readBody(req),
|
||||
handler: async ({ req, res, app, rawLedger: ledger, access, readBody }) => {
|
||||
const b = await readBody(),
|
||||
member = b.member ?? (b.role === 'assistant2' ? 'assistant2' : b.role === 'assistant' ? 'assistant' : 'owner');
|
||||
if (!TeamMembers.isActive(ledger, member)) fail('演示成员无效');
|
||||
const u = ledger.one(
|
||||
'SELECT u.id,u.name,u.role FROM users u JOIN team_user_members t ON t.user_id=u.id WHERE t.member=?',
|
||||
member,
|
||||
);
|
||||
checkAccount(u, { outside: access.outside, period: app.access.currentWindow() });
|
||||
const result = app.session(res, u);
|
||||
securityAudit(ledger, req, 'auth:' + u.id, '演示登录', who(u));
|
||||
return result;
|
||||
|
||||
@@ -8,7 +8,6 @@ const {
|
||||
exchangeCustomerPrintDocument,
|
||||
} = require('../../domains/printing/recovery-printing');
|
||||
const { HTML } = require('../http');
|
||||
const { readBody } = require('../middleware/body');
|
||||
|
||||
const STATUS = '/api/print-status/:kind(order|recovery)/:id(uuid)';
|
||||
|
||||
@@ -26,9 +25,9 @@ module.exports = [
|
||||
method: 'POST',
|
||||
path: STATUS,
|
||||
direct: true,
|
||||
handler: async ({ req, url, ledger, params: { kind, id }, actor }) => {
|
||||
handler: async ({ req, url, ledger, params: { kind, id }, actor, readBody }) => {
|
||||
PrintStatus.access(ledger, kind, id, actor);
|
||||
const body = await readBody(req);
|
||||
const body = await readBody();
|
||||
PrintStatus.access(ledger, kind, id, actor);
|
||||
return ledger.transact(
|
||||
req.headers['idempotency-key'],
|
||||
|
||||
@@ -4,7 +4,6 @@ const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
const { fail } = require('../../core/ledger');
|
||||
const { send } = require('../http');
|
||||
const { readBody } = require('../middleware/body');
|
||||
const { securityAudit } = require('../security-audit');
|
||||
|
||||
function csvText(value) {
|
||||
@@ -60,8 +59,8 @@ module.exports = [
|
||||
path: '/api/backup',
|
||||
role: 'owner',
|
||||
direct: true,
|
||||
handler: async ({ req, ledger, actor, app }) => {
|
||||
await readBody(req);
|
||||
handler: async ({ ledger, actor, app, readBody }) => {
|
||||
await readBody();
|
||||
const b = await app.doBackup();
|
||||
ledger.audit('system', '完整备份', actor, { name: b.name });
|
||||
return { name: b.name };
|
||||
@@ -87,8 +86,8 @@ module.exports = [
|
||||
path: '/api/sync',
|
||||
role: 'owner',
|
||||
direct: true,
|
||||
handler: async ({ req, app }) => {
|
||||
await readBody(req);
|
||||
handler: async ({ app, readBody }) => {
|
||||
await readBody();
|
||||
await app.sync.tick();
|
||||
return app.sync.status();
|
||||
},
|
||||
|
||||
@@ -8,6 +8,20 @@ const { notFound } = require('../http');
|
||||
const EMPLOYEE_ACTION = '/api/employees/:member(member)/:action(update|deactivate|reactivate|delete)';
|
||||
|
||||
module.exports = [
|
||||
{
|
||||
method: 'POST',
|
||||
path: '/api/business-hours/setup',
|
||||
auth: 'session',
|
||||
role: 'owner',
|
||||
direct: true,
|
||||
handler: async ({ app, ledger, actor, readBody }) => {
|
||||
const body = await readBody();
|
||||
if (app.access.currentWindow()?.state !== 'unset') fail('营业时间已设置,请重新打开台账。', 409);
|
||||
if (!body.businessHours) fail('请填写营业时间。');
|
||||
ShopSettings.update(ledger, { revision: body.revision, businessHours: body.businessHours }, actor);
|
||||
return { ok: true };
|
||||
},
|
||||
},
|
||||
{
|
||||
method: 'GET',
|
||||
path: '/api/shop-settings',
|
||||
|
||||
Reference in new issue
Block a user