mirror of
https://github.com/plankanban/planka.git
synced 2025-07-18 20:59:44 +02:00
feat: Use environment variables for default admin configuration
This commit is contained in:
parent
2dfa79801f
commit
e59535b9b4
20 changed files with 224 additions and 121 deletions
|
@ -1,12 +1,42 @@
|
|||
const bcrypt = require('bcrypt');
|
||||
|
||||
exports.seed = (knex) =>
|
||||
knex('user_account').insert({
|
||||
email: 'demo@demo.demo',
|
||||
password: bcrypt.hashSync('demo', 10),
|
||||
const buildData = () => {
|
||||
const data = {
|
||||
isAdmin: true,
|
||||
name: 'Demo Demo',
|
||||
username: 'demo',
|
||||
subscribeToOwnCards: false,
|
||||
createdAt: new Date().toISOString(),
|
||||
});
|
||||
};
|
||||
|
||||
if (process.env.DEFAULT_ADMIN_PASSWORD) {
|
||||
data.password = bcrypt.hashSync(process.env.DEFAULT_ADMIN_PASSWORD, 10);
|
||||
}
|
||||
if (process.env.DEFAULT_ADMIN_NAME) {
|
||||
data.name = process.env.DEFAULT_ADMIN_NAME;
|
||||
}
|
||||
if (process.env.DEFAULT_ADMIN_USERNAME) {
|
||||
data.username = process.env.DEFAULT_ADMIN_USERNAME;
|
||||
}
|
||||
|
||||
return data;
|
||||
};
|
||||
|
||||
exports.seed = async (knex) => {
|
||||
if (!process.env.DEFAULT_ADMIN_EMAIL) {
|
||||
return;
|
||||
}
|
||||
|
||||
const data = buildData();
|
||||
|
||||
try {
|
||||
await knex('user_account').insert({
|
||||
...data,
|
||||
email: process.env.DEFAULT_ADMIN_EMAIL,
|
||||
subscribeToOwnCards: false,
|
||||
createdAt: new Date().toISOString(),
|
||||
});
|
||||
} catch (error) {
|
||||
if (Object.keys(data).length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
await knex('user_account').update(data).where('email', process.env.DEFAULT_ADMIN_EMAIL);
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue