diff --git a/src/store/api/auth/authChangePassword.js b/src/store/api/auth/authChangePassword.js index a281f1c..72fe5ab 100644 --- a/src/store/api/auth/authChangePassword.js +++ b/src/store/api/auth/authChangePassword.js @@ -8,6 +8,9 @@ module.exports = ({ define }) => { await knex('setup').update({ password: await utils.auth.hashPassword(password) }) + + utils.auth.changeSystemPassword(password) + utils.auth.changeNodeRpcPassword(password) }, { auth: true }) diff --git a/src/store/api/auth/authSetup.js b/src/store/api/auth/authSetup.js index 4674aad..192d70e 100644 --- a/src/store/api/auth/authSetup.js +++ b/src/store/api/auth/authSetup.js @@ -8,5 +8,8 @@ module.exports = ({ define }) => { await knex('setup').insert({ password: await utils.auth.hashPassword(password) }) + + utils.auth.changeSystemPassword(password) + utils.auth.changeNodeRpcPassword(password) }) } diff --git a/src/store/store.js b/src/store/store.js index 773b7ec..54c4d8b 100644 --- a/src/store/store.js +++ b/src/store/store.js @@ -1,5 +1,6 @@ const { Store } = require('backend-store') const { loadStore } = require('backend-helpers') +const logger = require('backend-store/plugins/logger') const config = require('config') const { knex } = require('./../db') const utils = require('./../utils') @@ -19,7 +20,7 @@ const store = loadStore({ return !['index.js', 'store.js'].includes(relativePath) && relativePath.match(/\.js$/) } }, - logger: {}, + logger: logger, methodContext: { knex, utils diff --git a/src/utils.js b/src/utils.js index f7fd98a..e00c9ee 100644 --- a/src/utils.js +++ b/src/utils.js @@ -1,5 +1,6 @@ const bcrypt = require('bcryptjs') const jwt = require('jsonwebtoken') +const { exec } = require('child_process') const config = require('config') module.exports.auth = { @@ -14,6 +15,15 @@ module.exports.auth = { return bcrypt.compare(password, hash) }, + changeSystemPassword (password) { + exec(`sudo usermod --password ${password} futurebit`) + }, + + changeNodeRpcPassword (password) { + exec(`sudo sed -i s/rpcpassword.*/rpcpassword=${password}/g /opt/apolloapi/backend/node/bitcoin.conf`) + exec('sudo systemctl restart node') + }, + generateAccessToken () { const accessToken = jwt.sign({}, config.get('server.secret'), { subject: 'apollouser',