tracks/tracks/lib/tasks/reset_password.rake
lukemelia 9ac67bfc96 Applied Simon Rozet's patch to provide a rake task for resetting a user's password.
I vendored highline, a gem the task uses to ask the user to type the new password without echoing it.

Thanks, Simon! Closes #623.



git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@696 a4c988fc-2ded-0310-b66e-134b36920a42
2008-01-06 19:52:59 +00:00

25 lines
912 B
Ruby

namespace :tracks do
desc 'Replace the password of USER with a new one.'
task :password => :environment do
Dependencies.load_paths.unshift(File.dirname(__FILE__) + "/..../vendor/gems/highline-1.4.0/lib")
require "highline/import"
user = User.find_by_login(ENV['USER'])
if user.nil?
puts "Sorry, we couldn't find user '#{ENV['USER']}'. To specify a different user, pass USER=username to this task."
exit 0
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 }
begin
user.change_password(password, password_confirmation)
rescue ActiveRecord::RecordInvalid
puts "Sorry, we couldn't change #{ENV['USER']}'s password: "
user.errors.each_full { |msg| puts "- #{msg}\n" }
end
end
end