foreman/db/migrate/20100628123400_add_internal_auth.rb @ 8a65dff7
7a4ec5cf | Paul Kelly | 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
|
|||
40f9bcc1 | Ohad Levy | user = User.find_or_create_by_login(:login => "admin", :firstname => "Admin", :lastname => "User", :mail => "root@#{Facter.domain}")
|
|
user.update_attribute :admin, true
|
|||
7a4ec5cf | Paul Kelly | src = AuthSourceInternal.find_or_create_by_type "AuthSourceInternal"
|
|
src.update_attribute :name, "Internal"
|
|||
user.auth_source = src
|
|||
user.password="changeme"
|
|||
if user.save
|
|||
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
|