RubyGems.org

EasyRailsAuthentication

This project uses MIT-LICENSE. It's a standard rails plugin, so you can include it from your application's Gemfile or your plugin's gemspec.

Setup

The first thing you'll want to do is migrate your datebase to create its tables, using `rake easy_rails_authentication_engine:install:migrations`.

Then, in your ApplicationController, add these lines:

protected
  include EasyRailsAuthentication::AuthenticationHelper
  before_filter :require_authentication
  before_filter :require_administrator_priveleges

This will guarantee that all your pages can only be accessed by an administrator, but you can, of course, override that in individual controllers using `skip_before_filter …`. See examples in test/dummy/app/controllers/dummy_routes_controller.rb.

A few other basic setup requirements:

  1. Assets: Your application's javascripts and stylesheets manifests should include the plugin's appropriate index files using `//= require easy_rails_authentication` (for javascripts) and `*= require easy_rails_authentication` (for stylesheets).

  2. Configure the application's `config.action_mailer.default_url_options` since the plugin sends e-mails. Do this in config/environments/*.rb or in config/application.rb. Assuming you've set MyHost and MyPort to the appropriate values for your domain, configure as follows:

    config.action_mailer.default_url_options = { :host => "#{MyHost}:#{MyPort}" }
    
  3. Configure some EasyRailsAuthentication configuration parameters, as follows:

    EasyRailsAuthentication.configure do |config|
      config.contact_info = "..." # The way users should contact you with questions about their accounts.  Phone number, email, or both.
      config.send_mail_from = "..." # The email address that this application sends email from
      config.signature = "..." # The last line of all emails.  The name you go by, or "Cheers!" or whatever else you'd like
    end
    
  4. config/routes.rb must define a root route.

Partial templates

You can include partial templates for logging in an updating user information. In your view or layout:

<%= render "users/show" %>
<%= render "sessions/login" %>

Both of these templates will automatically detect when a user is logged. In that event, the former will not display, and the latter will replace the login form with a logout button.

Pages

Running `rake routes` will give you the full picture, but practically speaking, the following paths are the ones you may want to link to:

users_path (index of all users--only admins can view this)
edit_user_path (requires an ID to be passed as an arg)
new_user_path
login_path
forgot_password_path (for the user to request an e-mail with a link to reset his password)

API

`app/helpers/easy_rails_authentication/authentication_helper.rb` defines several functions useful for authentication. The ones you'll primarily need (in addition to the filters mentioned above) are:

logged_in?
logged_in_as?(user)
log_in_as(user)
log_out

Because these are helper functions, they are accessible from all views and helpers. They should also be accessible from all controllers if you've included the helper in your ApplicationController as described above.

When a user is created, the password is initialized to an unusable value. Only by the user following a unique link to set the password can the password be reset so the user can log in. To send the user an email with the link (which is automatically generated when the email is sent):

EasyRailsAuthentication::AuthenticationHelper.SendPasswordInitializationEmailTo(user_or_email)

Similarly, you can send a password recovery email to a user who forgot his password with either of:

EasyRailsAuthentication::AuthenticationHelper.SendPasswordRecoveryEmailTo(email)
EasyRailsAuthentication::AuthenticationHelper.ResendPasswordRecoveryEmailTo(email)

These two functions differ in that the former does not send the email if a password recovery is already in progress (i.e. a link has previously been generated and the password has not been reset yet) for that user.

There are also plenty of useful functions in other helper files, so take a look and you may find some code you want to re-use.

Contributing

The usual github for process. Contact info is in the gemspec file.

installgem install easy_rails_authentication
Authors

Isaac Betesh

5,974 total downloads 903 for this version
Owners

B8dc4b76792ff3c8cd993aa4c9c467f6

Gemfile
gem 'easy_rails_authentication', '~> 0.0.8'
Versions
  1. 0.0.8 December 6, 2012 (736 KB)
  2. 0.0.7 October 30, 2012 (627 KB)
  3. 0.0.6 October 30, 2012 (99 KB)
  4. 0.0.4 October 11, 2012 (552 KB)
  5. 0.0.3 October 10, 2012 (308 KB)
Show all versions (8 total)
Development Dependencies
  1. sqlite3 >= 0