Permalink
Browse files

* Fix host/port management

  • Loading branch information...
redox committed Dec 29, 2008
1 parent ae463c5 commit 26f9769dd134dbdc05fa3a9632c3e1eb4be1bcf3
Showing with 13 additions and 5 deletions.
  1. +11 −2 app/controllers/accounts_controller.rb
  2. +2 −3 app/controllers/application.rb
@@ -22,19 +22,28 @@ def logout
private
def do_login
+ config = YAML.load_file(File.join(Rails.root, 'config', 'database.yml'))[Rails.env]
+ host = config['host'] # overwrite user specified
+ host = params[:host] if host.blank?
+ host = 'localhost' if host.blank?
+ port = config['port']
+ port = nil if port.blank?
begin
ActiveRecord::Base.establish_connection :adapter => "mysql",
- :host => params[:host] || "localhost",
+ :host => host,
:username => params[:username],
:password => params[:password],
- :database => ''
+ :database => '',
+ :port => port
ActiveRecord::Base.connection.execute "show databases"
rescue
flash[:error] = ($!).to_s
return false
end
session[:username] = params[:username]
session[:password] = params[:password]
+ session[:host] = host
+ session[:port] = port
return true
end
@@ -31,14 +31,13 @@ def authenticate
return false
end
- @@config = YAML.load_file(File.join(Rails.root, 'config', 'database.yml'))[Rails.env]
def establish_connection
ActiveRecord::Base.establish_connection :username => session[:username],
:password => session[:password],
:adapter => 'mysql',
:database => '',
- :host => (@@config['host'] or 'localhost'),
- :port => @@config['port']
+ :host => session[:host],
+ :port => session[:port]
return true
end

0 comments on commit 26f9769

Please sign in to comment.