Created
March 9, 2011 15:21
-
-
Save petedickson/862376 to your computer and use it in GitHub Desktop.
Authenticate users via Infusionsoft
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SessionsController < ApplicationController | |
include ApiInfusionsoft | |
def new | |
end | |
def numeric?(object) | |
true if Float(object) rescue false | |
end | |
def create | |
user = api_data_authenticate_user(params[:session][:username], | |
params[:session][:password]) | |
if numeric?(user) | |
# Log the user in | |
flash.now[:message] = "User logged in successfully" | |
redirect_to "http://localhost:3000" | |
else | |
flash.now[:error] = "Please try again. The username/password combination is not correct." | |
# @title = "Sign in" | |
render 'new' | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
describe SessionsController do | |
render_views | |
describe "GET 'new'" do | |
it "should be successful" do | |
get :new | |
response.should be_success | |
end | |
end | |
describe "POST 'create'" do | |
describe "invalid login" do | |
before(:each) do | |
@attr = { :username => "petedickson", :password => "invalid" } | |
end | |
it "should re-render the 'new' page" do | |
post :create, :session => @attr | |
response.should render_template('new') | |
end | |
it "should have a flash.now message" do | |
post :create, :session => @attr | |
flash.now[:error].should =~ /please/i | |
end | |
end | |
end | |
end |
Can you post our initializer code too. Should work.
api_infusionsoft.rb (in initializers)...
ApiInfusionsoft.set_account_apiconn("nimacus.infusionsoft.com", "MY_API_KEY")
what the heck.. try this. Create a test controller. Include the ApiInfusionsoft, and then in the index action add this:
user = api_data_query(:Contact, 1, 0, { :Id => 454 }, ["Id", "FirstName", "LastName"])
logger.info "****here is the user: #{user.inspect}"
obviously, change the Id to an Id you know exists.
Browse to it and check your logs to see if it worked.
have you guys had any luck resolving this issue? i've also encountered it.
Hey.. send me a message with a gist of your code, and I'll have a look. Should be working fine.
hi nate,
here is a gist of my code:
https://gist.github.com/1041105
I've added notes there as well. I'm not doing anything special at this point, so if it works for you, it should work for me.
Is there anything I have to configure beyond the initializer or any other dependencies?
Best,
Hari
…On Jun 22, 2011, at 3:58 AM, nateleavitt wrote:
Hey.. send me a message with a gist of your code, and I'll have a look. Should be working fine.
##
Reply to this email directly or view it on GitHub:
https://gist.github.com/862376
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
NoMethodError in SessionsController#create
undefined method `api_perform' for nil:NilClass