Sha256: 1e87ee5e70d5ec4ae98eff0d4b0cb24a4a7ea74a7ef9b28ec4bba0b72122e384

Contents?: true

Size: 1.23 KB

Versions: 5

Compression:

Stored size: 1.23 KB

Contents

class AddInternalAuth < ActiveRecord::Migration

  def self.up
    add_column :users, :password_hash, :string, :limit => 128
    add_column :users, :password_salt, :string, :limit => 128

    User.reset_column_information

    user = User.unscoped.find_or_create_by_login(:login => "admin", :firstname => "Admin", :lastname => "User", :mail => "root@#{Facter.domain}")
    user.admin = true
    src  = AuthSourceInternal.find_or_create_by_type "AuthSourceInternal"
    src.update_attribute :name, "Internal"
    user.auth_source_id = src.id
    user.password="changeme"
    if user.save_without_auditing
      say "****************************************************************************************"
      say "The newly created internal account named admin has been allocated a password of 'changeme'"
      say "Set this to something else in the settings/users page"
      say "****************************************************************************************"
    else
      say user.errors.full_messages.join(", ")
    end
  end

  def self.down
    if (auth = AuthSourceInternal.first)
      auth.users.each {|u| u.destroy}
      auth.destroy
    end
    remove_column :users, :password_salt
    remove_column :users, :password_hash
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
foreman_discovery-1.0.0 test/foreman_app/db/migrate/20100628123400_add_internal_auth.rb
foreman_discovery-1.0.0.rc4 test/foreman_app/db/migrate/20100628123400_add_internal_auth.rb
foreman_discovery-1.0.0.rc3 test/foreman_app/db/migrate/20100628123400_add_internal_auth.rb
foreman_discovery-1.0.0.rc2 test/foreman_app/db/migrate/20100628123400_add_internal_auth.rb
foreman_discovery-1.0.0.rc1 test/foreman_app/db/migrate/20100628123400_add_internal_auth.rb