tracks/lib/tasks/tracks.rake

28 lines
857 B
Ruby
Raw Normal View History

2014-02-09 14:56:05 +01:00
namespace :tracks do
desc 'Replace the password of USER with a new one.'
task :password => :environment do
require "io/console"
2020-10-27 19:35:01 +02:00
2014-02-09 14:56:05 +01:00
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
2020-10-27 19:35:01 +02:00
end
2014-02-09 14:56:05 +01:00
puts "Changing Tracks password for #{ENV['USER']}."
print "New password: "
password = STDIN.noecho(&:gets).chomp
print "\nRetype new password: "
password_confirmation = STDIN.noecho(&:gets).chomp
puts
2020-10-27 19:35:01 +02:00
2014-02-09 14:56:05 +01:00
begin
user.change_password(password, password_confirmation)
puts "Password changed."
2014-02-09 14:56:05 +01:00
rescue ActiveRecord::RecordInvalid
puts "Sorry, we couldn't change #{ENV['USER']}'s password: "
user.errors.full_messages.each { |msg| puts "- #{msg}\n" }
2014-02-09 14:56:05 +01:00
end
end
end