Sha256: 784015af7430fe8b14802cf230b0e5200cbe870738e25590d96f41b13b0be06f

Contents?: true

Size: 1.1 KB

Versions: 10

Compression:

Stored size: 1.1 KB

Contents

require 'securerandom'

namespace :caseadilla do

  namespace :users do

    desc "Create default admin user"
    task create_admin: :environment do

      unless ENV.include?("email") and ENV.include?("first_name") and ENV.include?("last_name") and ENV.include?("password")
        raise "Usage: specify email address, first and last name, and a password. \nE.g. rake [task] email=mail@example.com first_name=John last_name=Doe password=password123"
      end

      admin = User.new({email: ENV['email'], first_name: ENV['first_name'], last_name: ENV['last_name'], password: ENV['password'] })

      unless admin.save
        puts "[Caseadilla] Failed: check that the account doesn't already exist."
      else
        puts "[Caseadilla] Created new admin user with email '#{ENV['email']}' and password '#{ENV['password']}'"
      end
      admin.role = Role.find_by_title 'admin'
      admin.save!
    end

    desc "Remove all users"
    task remove_all: :environment do
      users = User.all
      num_users = users.size
      users.destroy_all
      puts "[Caseadilla] Removed #{num_users} user(s)"
    end

  end

end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
caseadilla-0.0.19 lib/railties/tasks.rake
caseadilla-0.0.18 lib/railties/tasks.rake
caseadilla-0.0.17 lib/railties/tasks.rake
caseadilla-0.0.16 lib/railties/tasks.rake
caseadilla-0.0.15 lib/railties/tasks.rake
caseadilla-0.0.14 lib/railties/tasks.rake
caseadilla-0.0.13 lib/railties/tasks.rake
caseadilla-0.0.12 lib/railties/tasks.rake
caseadilla-0.0.11 lib/railties/tasks.rake
caseadilla-0.0.10 lib/railties/tasks.rake