From 7b33f2a9f1da70457a6b5e65dcae5686efbc4a31 Mon Sep 17 00:00:00 2001 From: Mateusz Blicharski Date: Mon, 5 Nov 2018 11:37:13 +0100 Subject: [PATCH 1/3] knexfile update --- knexfile.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/knexfile.js b/knexfile.js index d705eae..1759fee 100644 --- a/knexfile.js +++ b/knexfile.js @@ -1,6 +1,6 @@ const config = require('config') module.exports = { - client: 'pg', + client: 'sqlite', connection: config.get('db.url') } From f927a07f71074c103e32d77947e0aace5058fbd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20D=C4=99bski?= Date: Mon, 5 Nov 2018 14:05:35 +0100 Subject: [PATCH 2/3] Added ChangePassword API --- .../graphqlModules/Auth/AuthChangePassword.js | 21 +++++++++++++++++++ src/store/api/auth/authChangePassword.js | 12 +++++++++++ 2 files changed, 33 insertions(+) create mode 100644 src/graphql/graphqlModules/Auth/AuthChangePassword.js create mode 100644 src/store/api/auth/authChangePassword.js diff --git a/src/graphql/graphqlModules/Auth/AuthChangePassword.js b/src/graphql/graphqlModules/Auth/AuthChangePassword.js new file mode 100644 index 0000000..faa7dfb --- /dev/null +++ b/src/graphql/graphqlModules/Auth/AuthChangePassword.js @@ -0,0 +1,21 @@ +module.exports.typeDefs = ` + type AuthActions { + changePassword (input: AuthChangePasswordInput!): AuthChangePasswordOutput! + } + + input AuthChangePasswordInput { + password: String! + } + + type AuthChangePasswordOutput { + error: Error + } +` + +module.exports.resolvers = { + AuthActions: { + changePassword (root, args, { dispatch }) { + return dispatch('api/auth/changePassword', args.input) + } + } +} \ No newline at end of file diff --git a/src/store/api/auth/authChangePassword.js b/src/store/api/auth/authChangePassword.js new file mode 100644 index 0000000..a79210b --- /dev/null +++ b/src/store/api/auth/authChangePassword.js @@ -0,0 +1,12 @@ +module.exports = ({ define }) => { + define('changePassword', async ({ password }, { knex, errors, utils }) => { + // TODO transaction + const [ setup ] = await knex('setup').select('*').limit(1) + if (!setup) { + throw new errors.AuthorizationError('Setup not finished') + } + await knex('setup').update({ + password: await utils.auth.hashPassword(password) + }) + }) +} From bd3145254b4607006f930b08b2702ac480c2712b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20D=C4=99bski?= Date: Tue, 6 Nov 2018 08:52:42 +0100 Subject: [PATCH 3/3] Added auth flag to changePassword --- src/store/api/auth/authChangePassword.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/store/api/auth/authChangePassword.js b/src/store/api/auth/authChangePassword.js index a79210b..a281f1c 100644 --- a/src/store/api/auth/authChangePassword.js +++ b/src/store/api/auth/authChangePassword.js @@ -8,5 +8,7 @@ module.exports = ({ define }) => { await knex('setup').update({ password: await utils.auth.hashPassword(password) }) + }, { + auth: true }) }