diff --git a/migrations/manual_password_reset.js b/migrations/manual_password_reset.js index 7051e442d3..68b69cbbbe 100644 --- a/migrations/manual_password_reset.js +++ b/migrations/manual_password_reset.js @@ -1,19 +1,35 @@ -// node ./migrations/manual_password_reset.js +// EMAIL="x@y.com" node ./migrations/manual_password_reset.js +// Be sure to have PRODUCTION_DB in your config.json -//TODO: CHANGE -var dbserver = 'mongodb://node-a0.server.com:port/habitrpg', //Note, only include primary set - creds = {username:'', password:''}, - email = ''; +var nconf = require('nconf'), + path = require('path'); +nconf.argv().env().file('user', path.join(path.resolve(__dirname, '../config.json'))); -var utils = require('../website/src/utils'), +var Users = require('mongoskin').db(nconf.get("PRODUCTION_DB:URL"), nconf.get("PRODUCTION_DB").CREDS).collection('users'), + async = require('async'), + utils = require('../website/src/utils'), salt = utils.makeSalt(), newPassword = utils.makeSalt(), // use a salt as the new password too (they'll change it later) hashed_password = utils.encryptPassword(newPassword, salt); -console.log(newPassword); -require('mongoskin').db(dbserver, creds).collection('users') - .update({'auth.local.email':email}, { - $set:{ - 'auth.local.salt': salt, - 'auth.local.hashed_password': hashed_password - } - }, process.exit); + +async.waterfall([ + function(cb){ + Users.findItems({'auth.local.email':nconf.get("EMAIL")}, {auth:1}, cb); + }, + function(users, cb){ + if (users.length<1) return cb("User not found for that email"); + if (users.length>1) return cb("Multiple users for that email"); + var user = users[0]; + console.dir({username:user.auth.local.username, password: newPassword}); + Users.update({_id:user._id}, { + $set:{ + 'auth.local.salt': salt, + 'auth.local.hashed_password': hashed_password, + 'preferences.sleep': true + } + }, cb) + } +], function(err){ + if (err) console.log(err); + process.exit() +}); \ No newline at end of file