Skip to content
This repository has been archived by the owner on Feb 13, 2023. It is now read-only.

feat(36): Create a command-line tool to reset passwords #37

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions bin/reset-password.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env node
'use strict';
const meow = require('meow');
const models = require('../src/models');
const hashPassword = require("../src/helpers/hashPassword");
const shortid = require("shortid");


const cli = meow(`
Usage
$ reset-password <passportId>

Examples
$ reset-password 2569
`);

if (!cli.input[0]) {
throw new Error('passportId must be supplied')
}

const resetUserPass = async () => {

// noinspection JSUnresolvedVariable
const user = await models.users.findOne({
where: {passportId: cli.input[0]},
attributes: {exclude: ['password', 'imageRightsConsent']},
})

if (!user) {
throw new Error('User not found')
}

// not fort knox
const newPassword = shortid.generate()
const hashedNewPassword = await hashPassword.encrypt(newPassword)

try {
// noinspection JSUnresolvedVariable
await models.users.update(
{
password: hashedNewPassword
}, {
where: {
passportId: cli.input[0]
},
})

console.log(`

************************
User passportId ${cli.input[0]} got its password set to ${newPassword}
************************`)
} catch (e) {
console.error(e)
throw new Error('Error updating user password');
}
}

resetUserPass().then(() => process.exit())
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ node:
ports:
- "19461:17461"
volumes:
- ./bin:/var/www/bin
- ./config:/var/www/config
- ./src:/var/www/src
- ./package.json:/var/www/package.json
Expand Down
Loading