-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.js
128 lines (121 loc) · 3.92 KB
/
config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
'use strict';
import { join, resolve } from 'path';
import merge from 'lodash.merge';
const config = {
proxy: true,
debug: process.env.NODE_ENV !== 'production',
staticPath: join(__dirname, '../public'),
viewPath: join(__dirname, '../views'),
keys: ['auth', 'center'],
session: {
key: 'sid'
},
domain: '__domain__',
logo: '/logo.png',
favicon: '/logo.png',
terms: 'https://en.wikipedia.org/wiki/Terms_of_service',
tokenLimit: 3 * 3600,
recoveryTokenTTL: 5 * 60,
// I18N config
messages: {},
// OAuth config
isTOTP: true,
codeTTL: 10 * 60,
accessTokenTTL: 12 * 3600,
refreshTokenTTL: 30 * 24 * 3600,
// ORM config
orm: {
database: ':memory:',
dialect: 'sqlite',
modelPath: join(__dirname, 'models')
},
// Mail config
mail: {
templates: {
send_totp: {
subject: '[Important] The key of the dynamic token',
html: `
<p>Hello, <strong>{{username}}</strong>, following image is the key for dynamic token.</p>
<p><img src="cid:{{cid}}"/></p>
<p>Or you can use following email and secret key to register :</p>
<p>Email: {{email}}<br>Secret Key: {{key}}</p>
<p>You should download <strong>Takey</strong> to scan it.</p>
<p>iOS App: <a href="https://itunes.apple.com/cn/app/takey/id1447343446">https://itunes.apple.com/cn/app/takey/id1447343446</a><br>
Android App: <a href="https://dl.jsmartx.com/app/takey.apk">https://dl.jsmartx.com/app/takey.apk</a></p>
<p>Thanks!</p>
`
},
login_token: {
subject: '{{token}} is your sign in token',
html: `
Dear {{username}}
<br><br>Your dynamic token is <span style="font-weight: 500; color: #f4364c;">{{token}}</span>. It will be expired in 5 minutes.
<br><br><br><br>To make sure our emails arrive, please add {{sender}} to your contacts.
`
},
resetpwd_token: {
subject: '{{token}} is your retrieve password captcha',
html: `
<p>Hello, <strong>{{username}}</strong>, we heard that you lost your password. Sorry about that!<br>
But don’t worry! You can use the captcha to reset your password: <span style="font-weight: 500; color: #f4364c;">{{token}}</span>. It will be expired in 5 minutes.
</p>
<p>To make sure our emails arrive, please add {{sender}} to your contacts.</p>
`
}
}
},
routes: {
home: '/',
login: '/login',
logout: '/logout',
scan: '/scan',
qrcode: '/qrcode',
scan_login: '/scan_login',
password_reset: '/password_reset',
password_change: '/password_change',
login_token: '/login_token',
resetpwd_token: '/resetpwd_token',
resetpwd_auth: '/resetpwd_auth',
session: '/session',
user: '/user',
authorize: '/authorize',
access_token: '/access_token',
security: '/security',
security_change: '/security_change',
admin: {
users: '/admin',
search_user: '/admin/search_user',
clients: '/admin/clients',
roles: '/admin/roles',
send_totp: '/admin/send_totp',
add_client: '/admin/add_client',
generate_secret: '/admin/generate_secret',
add_role: '/admin/add_role',
delete_role: '/admin/delete_role'
}
}
};
export default function initConfig (param) {
if (typeof param === 'string') {
const customConfig = require(resolve(param));
merge(config, customConfig);
}
if (typeof param === 'object') {
merge(config, param);
}
if (!config.orm.dialectModulePath) {
const modulePath = join(process.cwd(), 'node_modules');
const moduleName = ({
sqlite: 'sqlite3',
mysql: 'mysql2',
mariadb: 'mysql2',
postgres: 'pg',
mssql: 'tedious'
})[config.orm.dialect];
config.orm.dialectModulePath = require.resolve(join(modulePath, moduleName));
}
if (!config.orm.logging) {
config.orm.logging = config.debug && console.log;
}
return config;
}