Sha256: 0a8a17ac5b3ffe167ac442c215557253db19b4ff2c0573162cb3dff513fed875

Contents?: true

Size: 1.23 KB

Versions: 11

Compression:

Stored size: 1.23 KB

Contents

# This module is included in your application controller which makes
# several methods available to all controllers and views. Here's a
# common example you might add to your application layout file.
# 
#   <%% if logged_in? %>
#     Welcome <%%= current_user.username %>! Not you?
#     <%%= link_to "Log out", logout_path %>
#   <%% else %>
#     <%%= link_to "Sign up", signup_path %> or
#     <%%= link_to "log in", login_path %>.
#   <%% end %>
# 
# You can also restrict unregistered users from accessing a controller using
# a before filter. For example.
# 
#   before_filter :login_required, :except => [:index, :show]
module Authentication
  def self.included(controller)
    controller.send :helper_method, :current_<%= user_singular_name %>, :logged_in?
    controller.filter_parameter_logging :password
  end
  
  def current_<%= user_singular_name %>
    @current_<%= user_singular_name %> ||= <%= user_class_name %>.find(session[:<%= user_singular_name %>_id]) if session[:<%= user_singular_name %>_id]
  end
  
  def logged_in?
    current_<%= user_singular_name %>
  end
  
  def login_required
    unless logged_in?
      flash[:error] = "You must first log in or sign up before accessing this page."
      redirect_to login_url
    end
  end
end

Version data entries

11 entries across 11 versions & 4 rubygems

Version Path
PeterCoulton-rotten-generators-0.7.0 rails_generators/rotten_authentication/templates/authentication.rb
PeterCoulton-rotten-generators-0.7.12 rails_generators/rotten_authentication/templates/authentication.rb
rotten-generators-0.9.0 rails_generators/rotten_authentication/templates/authentication.rb
rotten-generators-0.9.2 rails_generators/rotten_authentication/templates/authentication.rb
rotten-generators-0.9.3 rails_generators/rotten_authentication/templates/authentication.rb
rotten-generators-0.9.4 rails_generators/rotten_authentication/templates/authentication.rb
rotten-generators-0.9.5 rails_generators/rotten_authentication/templates/authentication.rb
rotten-generators-0.9.6 rails_generators/rotten_authentication/templates/authentication.rb
rotten-generators-0.9.7 rails_generators/rotten_authentication/templates/authentication.rb
rotten-rotten-generators-0.7.12 rails_generators/rotten_authentication/templates/authentication.rb
nifty-generators-0.2.4 rails_generators/nifty_authentication/templates/authentication.rb