lib/railties/tasks.rake in casein-4.0.0 vs lib/railties/tasks.rake in casein-5.0.0.0
- old
+ new
@@ -1,30 +1,32 @@
require 'authlogic'
+require 'securerandom'
namespace :casein do
-
+
namespace :users do
desc "Create default admin user"
- task :create_admin => :environment do
-
- raise "Usage: specify email address, e.g. rake [task] email=mail@caseincms.com" unless ENV.include?("email")
-
- admin = Casein::User.new( {:login => 'admin', :name => 'Admin', :email => ENV['email'], :access_level => $CASEIN_USER_ACCESS_LEVEL_ADMIN, :password => 'password', :password_confirmation => 'password'} )
-
+ task create_admin: :environment do
+
+ raise "Usage: specify email address, e.g. rake [task] email=mail@caseincms.com" unless ENV.include?("email")
+
+ random_password = random_string = SecureRandom.hex
+ admin = Casein::AdminUser.new({ login: 'admin', name: 'Admin', email: ENV['email'], access_level: $CASEIN_USER_ACCESS_LEVEL_ADMIN, password: random_password, password_confirmation: random_password })
+
unless admin.save
puts "[Casein] Failed: check that the 'admin' account doesn't already exist."
else
- puts "[Casein] Created new admin user with login 'admin' and password 'password'"
- end
+ puts "[Casein] Created new admin user with username 'admin' and password '#{random_password}'"
+ end
end
desc "Remove all users"
- task :remove_all => :environment do
- users = Casein::User.find(:all)
+ task remove_all: :environment do
+ users = Casein::AdminUser.all
num_users = users.size
- users.each { |user| user.destroy }
- puts "[Casein] Removed #{num_users} user(s)"
+ users.destroy_all
+ puts "[Casein] Removed #{num_users} user(s)"
end
end
end
\ No newline at end of file