Skip to content

Instantly share code, notes, and snippets.

@sandover
Created March 19, 2010 16:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sandover/337801 to your computer and use it in GitHub Desktop.
Save sandover/337801 to your computer and use it in GitHub Desktop.
def auth_by_eso( username, password )
begin
driver = SOAP::WSDLDriverFactory.new(ESO_WEB_SERVICE_URL).create_rpc_driver
result = driver.Authenticate( { :username => username, :password => password} )
result.authenticateResult == 'VALID_USER'
rescue
logger.info " >> ESO authentication failed for #{params[:action]} in #{params[:id]}"
false
end
end
def authenticate
authenticate_or_request_with_http_basic do | username,password |
return false if username.blank? || password.blank?
username.strip!.downcase!
# Authenticate by session cookie
if session[:user_id]
@current_user = User.find_by_username( session[:user_id] )
# Authenticate by access list (or by calling ESO webservice)
elsif ACCESS_LIST[ username ] == password || auth_by_eso( username, password )
session[:user_id] = username # Put user in session table; instant lookup next time
@current_user = User.find_or_create_by_username( username )
else
generate_render("401 Unauthorized user or incorrect password: #{username}")
false
end
end
def generate_render( render_msg )
@result = render_msg
render :text => render_msg, :status => render_msg.split(" ").first
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment