X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=scripts%2Freset-password.ts;h=6126c3cd09fa9da04c57b1c52852ad3196627f66;hb=0e9c3b2810aa3fc8bbf5275e42ce621efc6cdb66;hp=50e11c69c0195fbe4b7d446e7c0864d0ae5e30d2;hpb=75d612ce3ca9d6f69fe8e4e83dc3070d9ab56615;p=github%2FChocobozzz%2FPeerTube.git diff --git a/scripts/reset-password.ts b/scripts/reset-password.ts index 50e11c69c..6126c3cd0 100755 --- a/scripts/reset-password.ts +++ b/scripts/reset-password.ts @@ -1,26 +1,28 @@ -import * as program from 'commander' +import { registerTSPaths } from '../server/helpers/register-ts-paths' +registerTSPaths() -import { database as db } from '../server/initializers/database' +import * as program from 'commander' +import { initDatabaseModels } from '../server/initializers' +import { UserModel } from '../server/models/account/user' +import { isUserPasswordValid } from '../server/helpers/custom-validators/users' program .option('-u, --user [user]', 'User') .parse(process.argv) -if (program.user === undefined) { +if (program['user'] === undefined) { console.error('All parameters are mandatory.') process.exit(-1) } -db.init(true, function () { - db.User.loadByUsername(program.user, function (err, user) { - if (err) { - console.error(err) - return - } - +initDatabaseModels(true) + .then(() => { + return UserModel.loadByUsername(program['user']) + }) + .then(user => { if (!user) { console.error('User unknown.') - return + process.exit(-1) } const readline = require('readline') @@ -38,17 +40,16 @@ db.init(true, function () { console.log('New password?') rl.on('line', function (password) { - user.password = password + if (!isUserPasswordValid(password)) { + console.error('New password is invalid.') + process.exit(-1) + } - user.save().asCallback(function (err) { - if (err) { - console.error(err) - } else { - console.log('User password updated.') - } + user.password = password - process.exit(0) - }) + user.save() + .then(() => console.log('User password updated.')) + .catch(err => console.error(err)) + .finally(() => process.exit(0)) }) }) -})