Sha256: a177719882a26b2313168dd88067858617758ec6492c5cdd6f65b86d345d67bf

Contents?: true

Size: 1.2 KB

Versions: 5

Compression:

Stored size: 1.2 KB

Contents

desc "Creates an admin user"
namespace :protected do
  task :create_admin => [:environment] do
    puts "Creating a Admin User"

    puts "Please enter first name"
    first_name = $stdin.gets.chomp

    puts "Please enter last name"
    last_name = $stdin.gets.chomp

    puts "Please enter login (between 6 and 64 chars; no whitespace; [A-Za-z0-9]; special chars (-, _, .) and should not be in the beginning or end)"
    login = $stdin.gets.chomp

    puts "Please enter email (Password will be emailed to this address):"
    email = $stdin.gets.chomp

    # Create user 
    params = {
      :first_name => "Admin",
      :last_name => "User",
      :company => "XYZ Inc.",
      :login => "",
      :email => "",
      :password => "P@ssw0rd"
    }.merge(:first_name => first_name, :last_name => last_name, :email => email, :login => login)

    user = nil
    begin
      user = Protected::User.new(params)
      user.is_admin = true
      user.save
    rescue => e
      puts "Please correct the follwing errors and try again."

      user.errors.full_messages.each_with_index { |msg, i|
        puts "#{i+1}. #{msg}"
      } unless user.nil?

      puts "#{e.inspect}"
      puts "#{e.backtrace}"
    end    
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
protected-1.0.4 lib/tasks/protected_tasks.rake
protected-1.0.3 lib/tasks/protected_tasks.rake
protected-1.0.2 lib/tasks/protected_tasks.rake
protected-1.0.1 lib/tasks/protected_tasks.rake
protected-1.0.0 lib/tasks/protected_tasks.rake