Sha256: 1ae4bb5a4eb3d00b8095c8b461395850c9e9a0355c00010b8b121fa61c4c2652

Contents?: true

Size: 1.01 KB

Versions: 4

Compression:

Stored size: 1.01 KB

Contents

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 [(optional) password=mypassword]" unless ENV.include?("email")
      password = ENV['password'] || SecureRandom.hex
      admin = Casein::AdminUser.new({ login: 'admin', name: 'Admin', email: ENV['email'], access_level: $CASEIN_USER_ACCESS_LEVEL_ADMIN, password: password, password_confirmation: password })

      unless admin.save
        puts "[Casein] Failed. Rails said:"
        puts admin.errors.full_messages.join("\n")
      else
        puts "[Casein] Created new admin user with username 'admin' and password '#{password}'"
      end
    end

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

  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
casein-5.3.2.0 lib/railties/tasks.rake
casein-5.3.1.0 lib/railties/tasks.rake
casein-5.3.0.0 lib/railties/tasks.rake
casein-5.2.0.0 lib/railties/tasks.rake