diff --git a/services/web/app/src/models/User.js b/services/web/app/src/models/User.js index 988e020385..d1b14e0195 100644 --- a/services/web/app/src/models/User.js +++ b/services/web/app/src/models/User.js @@ -97,6 +97,9 @@ const UserSchema = new Schema({ default: Settings.defaultFeatures.referencesSearch } }, + // when auto-merged from SL and must-reconfirm is set, we may end up using + // `sharelatexHashedPassword` to recover accounts... + sharelatexHashedPassword: String, must_reconfirm: { type: Boolean, default: false }, referal_id: { type: String, diff --git a/services/web/scripts/copy_old_sharelatex_passwords.js b/services/web/scripts/copy_old_sharelatex_passwords.js new file mode 100644 index 0000000000..1933a4474b --- /dev/null +++ b/services/web/scripts/copy_old_sharelatex_passwords.js @@ -0,0 +1,40 @@ +const { db } = require('../app/src/infrastructure/mongojs') +const Async = require('async') +const minimist = require('minimist') + +const argv = minimist(process.argv.slice(2)) +const limit = argv.limit + +if (!limit) { + console.log('Please supply an async limit with --limit') + process.exit(1) +} + +db.users.find( + { hashedPassword: { $exists: 1 }, sharelatexHashedPassword: { $exists: 0 } }, + { hashedPassword: 1 }, + (err, users) => { + if (err) { + throw err + } + + Async.eachLimit( + users, + limit, + (user, cb) => { + db.users.update( + { _id: user._id }, + { $set: { sharelatexHashedPassword: user.hashedPassword } }, + cb + ) + }, + err => { + if (err) { + throw err + } + console.log('finished') + process.exit(0) + } + ) + } +)