mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
move create-admin-user and delete-user to grunt folder
This commit is contained in:
parent
a2cb2b68eb
commit
7bfa3f97e7
2 changed files with 57 additions and 0 deletions
|
@ -19,6 +19,7 @@ module.exports = (grunt) ->
|
||||||
grunt.loadNpmTasks 'grunt-concurrent'
|
grunt.loadNpmTasks 'grunt-concurrent'
|
||||||
grunt.loadNpmTasks "grunt-contrib-coffee"
|
grunt.loadNpmTasks "grunt-contrib-coffee"
|
||||||
grunt.loadNpmTasks "grunt-shell"
|
grunt.loadNpmTasks "grunt-shell"
|
||||||
|
require('load-grunt-config')(grunt)
|
||||||
|
|
||||||
|
|
||||||
execute = {}
|
execute = {}
|
||||||
|
|
56
grunt/CreateAndDestoryUsers.coffee
Normal file
56
grunt/CreateAndDestoryUsers.coffee
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
|
||||||
|
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 joe@example.com", () ->
|
||||||
|
done = @async()
|
||||||
|
email = grunt.option("email")
|
||||||
|
if !email?
|
||||||
|
console.error "Usage: grunt create-admin-user --email joe@example.com"
|
||||||
|
process.exit(1)
|
||||||
|
|
||||||
|
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
|
||||||
|
user.save (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:
|
||||||
|
|
||||||
|
#{settings.siteUrl}/user/password/set?passwordResetToken=#{token}
|
||||||
|
|
||||||
|
"""
|
||||||
|
done()
|
||||||
|
|
||||||
|
grunt.registerTask 'delete-user', "deletes a user and all their data, Usage: grunt delete-user --email joe@example.com", () ->
|
||||||
|
done = @async()
|
||||||
|
email = grunt.option("email")
|
||||||
|
if !email?
|
||||||
|
console.error "Usage: grunt delete-user --email joe@example.com"
|
||||||
|
process.exit(1)
|
||||||
|
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
|
||||||
|
done()
|
Loading…
Reference in a new issue