restore reset_password rake task

This commit is contained in:
Reinier Balt 2014-02-09 14:56:05 +01:00
parent e0336f578e
commit a67f88bcfa
3 changed files with 27 additions and 0 deletions

View file

@ -31,6 +31,7 @@ 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'

View file

@ -105,6 +105,7 @@ GEM
ffi (1.9.3)
gherkin (2.12.2)
multi_json (~> 1.3)
highline (1.6.20)
hike (1.2.3)
htmlentities (4.3.1)
i18n (0.6.9)
@ -226,6 +227,7 @@ DEPENDENCIES
cucumber-rails
database_cleaner
factory_girl_rails
highline
htmlentities
jquery-rails
json

View file

@ -0,0 +1,24 @@
namespace :tracks do
desc 'Replace the password of USER with a new one.'
task :password => :environment do
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