I am building an application that requires a C++ program to access the
Rails web application using POST. Now, I just added user authentication
to the mix and it has made things more interesting.
I’m using basic authentication as shown in the AWDWR and Rails Recipes
books. I can now get my C++ program to submit the user credentials to
the login/login page. All I want the login page to do (in this case) is
to:
- Set the session cookie and return it to me (so that I can pass it up
when I submit the data to the main form) - Indicate a success code - Success/ Failed.
The login action is also used by other parts of the web application
which requires it to redirect to:
- Either the action saved in the session
- the Administration index page
My C++ Client has a custom user_agent setting so that I know when the
request has come from it. Now, I’m trying to figure out how to return a
specific value to this client only - hence, the need to render nothing
(special) and go to no specific URL. Any ideas? This is what my
login/login action looks like.
def login
session[:user_id] = nil
if request.post?
user = User.authenticate(params[:name], params[:password])
if user
session[:user_id] = user.id
if session[:intended_action].nil? ||
session[:intended_controller].nil?
if (@request.env[‘HTTP_USER_AGENT’] == “MyCustomCClient”)
#did it come from my C++ program?
#### <---- I need something here -----> ####
else
redirect_to(:action => “index”) #deals with direct
access to /login/login
end
else
redirect_to :action => session[:intended_action],
:controller => session[:intended_controller]
end
else
flash[:notice] = “Invalid user/password combination”
end
end
end
Thanks,
Mohit.