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
- 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.
session[:user_id] = nil
user = User.authenticate(params[:name], params[:password])
session[:user_id] = user.id
if session[:intended_action].nil? ||
if (@request.env[‘HTTP_USER_AGENT’] == “MyCustomCClient”)
#did it come from my C++ program?
#### <---- I need something here -----> ####
redirect_to(:action => “index”) #deals with direct
access to /login/login
redirect_to :action => session[:intended_action],
:controller => session[:intended_controller]
flash[:notice] = “Invalid user/password combination”