Newby needs advice on membership function

I am developing a support ticket system in Ruby and need to know if
there are any modules or anything that can be added to a project to
require a user to log in to the system first and then be allowed access
to the support ticket system.

If not, how would I go about verifying if a user is logged in before
being allowed to view the pages in the site?

I appreciate the advice!

[email protected] wrote:

I am developing a support ticket system in Ruby and need to know if
there are any modules or anything that can be added to a project to
require a user to log in to the system first and then be allowed access
to the support ticket system.

If not, how would I go about verifying if a user is logged in before
being allowed to view the pages in the site?

I appreciate the advice!

Use a before_filter to handle things like this. Filter can run before
all actions in the application, and if a filter renders, redirects, or
returns “false”, then the action that is being called is never executed.

Here is a simple before_filter setup that will deny anyone access to all
action in a controller.

http://pastie.caboo.se/16469

there are several generators and plugins for authentication, although i
have not used any of them.

in your controller though, you should add something like

before_filter :check_authentication

with a protected check_authentication method in your controller. in
that, you can check to see if a use is logged in, if not, you can
redirect to your login page to prompt the user.

hope that helps some.

Alex,

Thanks for the simple explanation. That helped a lot. However, I have
another question. You are setting the session[:user_id] in your
ApplicationController. How do I make that persistent throughout my
application? It does not appear to be setting the session variable as a
“global” option in the ApplicationController. When I click a link to
another :controller in the same application the other controller can’t
retrieve that session information. Is there a trick I am missing?

Thanks again for your help.

Andrew