From cb3b79407d53731b9ecdd169435d38894eabeb6b Mon Sep 17 00:00:00 2001 From: Pavel Penkov Date: Mon, 10 Jun 2013 05:56:51 +0400 Subject: [PATCH] Added admin:create rake task --- Gemfile | 1 + Gemfile.lock | 1 + lib/tasks/admin.rake | 23 +++++++++++++++++++++++ 3 files changed, 25 insertions(+) create mode 100644 lib/tasks/admin.rake diff --git a/Gemfile b/Gemfile index bb147414f..20fb0ec67 100644 --- a/Gemfile +++ b/Gemfile @@ -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' diff --git a/Gemfile.lock b/Gemfile.lock index c3bb60784..3460302fe 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -503,6 +503,7 @@ DEPENDENCIES guard-rspec guard-spork has_ip_address + highline hiredis image_optim image_sorcery diff --git a/lib/tasks/admin.rake b/lib/tasks/admin.rake new file mode 100644 index 000000000..0579fb355 --- /dev/null +++ b/lib/tasks/admin.rake @@ -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