Merge pull request #996 from PavelPenkov/admin_rake_task

Added admin:create rake task
This commit is contained in:
Sam 2013-06-09 22:30:48 -07:00
commit 77fac7ea41
3 changed files with 25 additions and 0 deletions

View File

@ -65,6 +65,7 @@ gem 'strong_parameters' # remove when we upgrade to Rails 4
gem 'therubyracer', require: 'v8'
gem 'thin'
gem 'diffy', require: false
gem 'highline', require: false
# Gem that enables support for plugins. It is required.
gem 'discourse_plugin', path: 'vendor/gems/discourse_plugin'

View File

@ -503,6 +503,7 @@ DEPENDENCIES
guard-rspec
guard-spork
has_ip_address
highline
hiredis
image_optim
image_sorcery

23
lib/tasks/admin.rake Normal file
View File

@ -0,0 +1,23 @@
desc "Creates a forum administrator"
task "admin:create" => :environment do
require 'highline/import'
begin
admin = User.new
admin.email = ask("Email:")
admin.username = "admin"
begin
password = ask("Password:") {|q| q.echo = false}
password_confirmation = ask("Repeat password:") {|q| q.echo = false}
end while password != password_confirmation
admin.password = password
# admin.email_confirmed = true
saved = admin.save
if !saved
puts admin.errors.full_messages.join("\n")
next
end
end while !saved
admin.grant_admin!
admin.change_trust_level!(TrustLevel.levels.max_by{|k, v| v}[0])
admin.email_tokens.update_all confirmed: true
end