Require only stdlib for password reset rake task

This commit is contained in:
Dan Rice 2014-05-15 22:35:28 -04:00
parent 1b3543c5de
commit 4a3d5a74e6
3 changed files with 8 additions and 7 deletions

View file

@ -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