From 4a3d5a74e64b34c799cf7de03e482a4f1f345a72 Mon Sep 17 00:00:00 2001 From: Dan Rice Date: Thu, 15 May 2014 22:35:28 -0400 Subject: [PATCH] Require only stdlib for password reset rake task --- Gemfile | 1 - Gemfile.lock | 2 -- lib/tasks/tracks.rake | 12 ++++++++---- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Gemfile b/Gemfile index 34284496..6e9e672a 100644 --- a/Gemfile +++ b/Gemfile @@ -31,7 +31,6 @@ gem "htmlentities" gem "swf_fu" gem "rails_autolink" gem "cache_digests" -gem "highline" # for reset_password rake task # To use ActiveModel has_secure_password gem 'bcrypt-ruby', '~> 3.0.0' diff --git a/Gemfile.lock b/Gemfile.lock index 2a915b74..918ab9fb 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -95,7 +95,6 @@ GEM ffi (1.9.3) gherkin (2.12.2) multi_json (~> 1.3) - highline (1.6.21) hike (1.2.3) htmlentities (4.3.1) i18n (0.6.9) @@ -218,7 +217,6 @@ DEPENDENCIES cucumber-rails database_cleaner factory_girl_rails - highline htmlentities jquery-rails json diff --git a/lib/tasks/tracks.rake b/lib/tasks/tracks.rake index 2a5ef952..f6efb97f 100644 --- a/lib/tasks/tracks.rake +++ b/lib/tasks/tracks.rake @@ -1,7 +1,7 @@ namespace :tracks do desc 'Replace the password of USER with a new one.' task :password => :environment do - require "highline/import" + require "io/console" user = User.find_by_login(ENV['USER']) if user.nil? @@ -10,14 +10,18 @@ namespace :tracks do end puts "Changing Tracks password for #{ENV['USER']}." - password = ask("New password: ") { |q| q.echo = false } - password_confirmation = ask('Retype new password: ') { |q| q.echo = false } + print "New password: " + password = STDIN.noecho(&:gets).chomp + print "\nRetype new password: " + password_confirmation = STDIN.noecho(&:gets).chomp + puts begin user.change_password(password, password_confirmation) + puts "Password changed." rescue ActiveRecord::RecordInvalid puts "Sorry, we couldn't change #{ENV['USER']}'s password: " - user.errors.each_full { |msg| puts "- #{msg}\n" } + user.errors.full_messages.each { |msg| puts "- #{msg}\n" } end end