Restful Authentication plugin for you to generate a REST-style authentication system template, apart from support for basic user management and authentication functions, have an optional e-mail activation.
Author: Rick Olson
License: Rails' (MIT)
SVN Warehouse: http://svn.techno-weenie.net/projects/plugins/restful_authentication/
Installation
. / script / plugin install http://svn.techno-weenie.net/projects/plugins/restful_authentication/
Use
1. To generate the framework code. / Script / generate authenticated user sessions - include-activation
This will generate a model, as well as two controller:
Models / user.rb, save the user's log in information
Controllers / users_controller.rb, providing a simple user management features
Controllers / sessions_controller.rb, providing user authentication support
-Include-activation parameters to decide whether or not to generate a new activation code sent to registered users of the code (usually not required).
2. This step is optional, if you want your URL look more in line with the practice of some, then add at route.rb:
map.signup '/ signup',: controller => 'users',: action =>' new '
map.login '/ login',: controller => 'sessions',: action =>' new '
map.logout '/ logout',: controller => 'sessions',: action =>' destroy '
If you would like to achieve: When the user enters the system directly show http://localhost:3000/ log interface, then you want to delete. / Public / index.html file, and then add routing:
map.connect '/',: controller => 'sessions',: action =>' new '
3. At the entrance of your system to add certification systems such as the entrance for the company's index page, then the index in the Ways CompanyController add authentication, as follows:
class CompaniesController <ApplicationController
include AuthenticatedSystem
before_filter: login_required
def index
if defined? (current_user) and (not current_user.nil?) then
@ companies = Company.find (: all)
respond_to do | format |
format.html # index.html.erb
format.xml (render: xml => @ companies)
end
else
redirect_to new_session_path
end
end
..............
end
Then when you first enter in the address column when the system will automatically http://localhost:3000/companies Jump to
http://localhost:3000/session/new, that is, log interface, enter the user name, password and click Login, if the page does not jump, then you need to modify User (Model) authentication methods authenticate, modified into the following:
def self.authenticate (login, password)
# The original code is as follows, involving activated_at IS NOT NULL, that is, Step 1 to generate the framework of the use of the parameters
#-Include-activation of the reason, may result in authentication failure
# U = find: first,: conditions => [ 'login =? And activated_at IS NOT NULL', login]
# The revised code is as follows
u = find_by_login (login) # need to get the salt
u & & u.authenticated? (password)? u: nil
end
4. After the success of control to verify the location of the page Jump: Modify SeesionController, find redirect_back_or_default ('/'), be amended to your home, such as redirect_back_or_default ( '/ companies'), this proved to be successful after the Jump to list of conpany .
5. Reference







