Commit 7bfa3f97 authored by Henry Oswald's avatar Henry Oswald
Browse files

move create-admin-user and delete-user to grunt folder

parent a2cb2b68
......@@ -19,6 +19,7 @@ module.exports = (grunt) ->
grunt.loadNpmTasks 'grunt-concurrent'
grunt.loadNpmTasks "grunt-contrib-coffee"
grunt.loadNpmTasks "grunt-shell"
execute = {}
module.exports = (grunt) ->
grunt.registerTask 'create-admin-user', "Create a user with the given email address and make them an admin. Update in place if the user already exists. Usage: grunt create-admin-user --email", () ->
done = @async()
email = grunt.option("email")
if !email?
console.error "Usage: grunt create-admin-user --email"
settings = require "settings-sharelatex"
UserRegistrationHandler = require "../web/app/js/Features/User/UserRegistrationHandler"
OneTimeTokenHandler = require "../web/app/js/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 (error) ->
throw error if error?
ONE_WEEK = 7 * 24 * 60 * 60 # seconds
OneTimeTokenHandler.getNewToken user._id, { expiresIn: ONE_WEEK }, (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:
grunt.registerTask 'delete-user', "deletes a user and all their data, Usage: grunt delete-user --email", () ->
done = @async()
email = grunt.option("email")
if !email?
console.error "Usage: grunt delete-user --email"
settings = require "settings-sharelatex"
UserGetter = require "../web/app/js/Features/User/UserGetter"
UserDeleter = require "../web/app/js/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
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment