-
Notifications
You must be signed in to change notification settings - Fork 693
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1091 from Mailtrain-org/fix-1046
Fix for #1046
- Loading branch information
Showing
3 changed files
with
113 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
'use strict'; | ||
|
||
const log = require('../lib/log'); | ||
const dbcheck = require('../lib/dbcheck'); | ||
const knex = require('../lib/knex'); | ||
const {getAdminId} = require("../../shared/users"); | ||
const bluebird = require('bluebird'); | ||
const bcrypt = require('bcrypt-nodejs'); | ||
const bcryptHash = bluebird.promisify(bcrypt.hash.bind(bcrypt)); | ||
|
||
async function init() { | ||
const args = process.argv.slice(2); | ||
|
||
if (args.length !== 2) { | ||
log.error('Usage: NODE_ENV=production node setup/docker-entrypoint-db-setup.js <admin password> <admin access token>') | ||
return; | ||
} | ||
|
||
const passwd = args[0]; | ||
const accessToken = args[1]; | ||
|
||
await dbcheck(); | ||
await knex.migrate.latest(); | ||
|
||
|
||
const hashedPasswd = await bcryptHash(passwd, null, null); | ||
await knex('users').where({id: getAdminId()}).update({password: hashedPasswd}); | ||
|
||
if (accessToken !== '') { | ||
await knex('users').where({id: getAdminId()}).update({access_token: accessToken}); | ||
} | ||
|
||
process.exit(0); | ||
} | ||
|
||
init().catch(err => {log.error('', err); process.exit(1); }); | ||
|
||
|