mirror of
https://github.com/sudoxnym/habitica.git
synced 2026-04-14 19:56:23 +00:00
feat(auth): update manual_password_reset so can pull creds from
config.json, and email from CLI. Much easier when updating en-masse
This commit is contained in:
parent
6ed0ff289f
commit
8b04773b2e
1 changed files with 30 additions and 14 deletions
|
|
@ -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()
|
||||
});
|
||||
Loading…
Reference in a new issue