mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-14 20:40:17 -05:00
[misc] keep up with web changes -- add waitForDb wrapper for tasks
This commit is contained in:
parent
1110d0f867
commit
fe3edd7197
1 changed files with 37 additions and 33 deletions
|
@ -9,31 +9,33 @@ module.exports = (grunt) ->
|
|||
process.exit(1)
|
||||
|
||||
settings = require "settings-sharelatex"
|
||||
mongodb = require "../web/app/src/infrastructure/mongodb"
|
||||
UserRegistrationHandler = require "../web/app/src/Features/User/UserRegistrationHandler"
|
||||
OneTimeTokenHandler = require "../web/app/src/Features/Security/OneTimeTokenHandler"
|
||||
UserRegistrationHandler.registerNewUser {
|
||||
email: email
|
||||
password: require("crypto").randomBytes(32).toString("hex")
|
||||
}, (error, user) ->
|
||||
if error? and error?.message != "EmailAlreadyRegistered"
|
||||
throw error
|
||||
user.isAdmin = true
|
||||
user.save (error) ->
|
||||
throw error if error?
|
||||
ONE_WEEK = 7 * 24 * 60 * 60 # seconds
|
||||
OneTimeTokenHandler.getNewToken "password", { expiresIn: ONE_WEEK, email:user.email, user_id: user._id.toString() }, (err, token)->
|
||||
return next(err) if err?
|
||||
|
||||
console.log ""
|
||||
console.log """
|
||||
Successfully created #{email} as an admin user.
|
||||
|
||||
Please visit the following URL to set a password for #{email} and log in:
|
||||
|
||||
#{settings.siteUrl}/user/password/set?passwordResetToken=#{token}
|
||||
|
||||
"""
|
||||
done()
|
||||
mongodb.waitForDb().then () ->
|
||||
UserRegistrationHandler.registerNewUser {
|
||||
email: email
|
||||
password: require("crypto").randomBytes(32).toString("hex")
|
||||
}, (error, user) ->
|
||||
if error? and error?.message != "EmailAlreadyRegistered"
|
||||
throw error
|
||||
user.isAdmin = true
|
||||
user.save (error) ->
|
||||
throw error if error?
|
||||
ONE_WEEK = 7 * 24 * 60 * 60 # seconds
|
||||
OneTimeTokenHandler.getNewToken "password", { expiresIn: ONE_WEEK, email:user.email, user_id: user._id.toString() }, (err, token)->
|
||||
return next(err) if err?
|
||||
|
||||
console.log ""
|
||||
console.log """
|
||||
Successfully created #{email} as an admin user.
|
||||
|
||||
Please visit the following URL to set a password for #{email} and log in:
|
||||
|
||||
#{settings.siteUrl}/user/password/set?passwordResetToken=#{token}
|
||||
|
||||
"""
|
||||
done()
|
||||
|
||||
grunt.registerTask 'user:delete', "deletes a user and all their data, Usage: grunt user:delete --email joe@example.com", () ->
|
||||
done = @async()
|
||||
|
@ -42,15 +44,17 @@ module.exports = (grunt) ->
|
|||
console.error "Usage: grunt user:delete --email=joe@example.com"
|
||||
process.exit(1)
|
||||
settings = require "settings-sharelatex"
|
||||
mongodb = require "../web/app/src/infrastructure/mongodb"
|
||||
UserGetter = require "../web/app/src/Features/User/UserGetter"
|
||||
UserDeleter = require "../web/app/src/Features/User/UserDeleter"
|
||||
UserGetter.getUser email:email, (error, user) ->
|
||||
if error?
|
||||
throw error
|
||||
if !user?
|
||||
console.log("user #{email} not in database, potentially already deleted")
|
||||
return done()
|
||||
UserDeleter.deleteUser user._id, (err)->
|
||||
if err?
|
||||
throw err
|
||||
done()
|
||||
mongodb.waitForDb().then () ->
|
||||
UserGetter.getUser email:email, (error, user) ->
|
||||
if error?
|
||||
throw error
|
||||
if !user?
|
||||
console.log("user #{email} not in database, potentially already deleted")
|
||||
return done()
|
||||
UserDeleter.deleteUser user._id, (err)->
|
||||
if err?
|
||||
throw err
|
||||
done()
|
||||
|
|
Loading…
Reference in a new issue