Sha256: 449f6f016a677d8ec83956da1797f2d0b99f9b9d44bea309fa25ddb2227ece31

Contents?: true

Size: 1.19 KB

Versions: 18

Compression:

Stored size: 1.19 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?
  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

18 entries across 18 versions & 3 rubygems

Version Path
polly-nifty-generators-0.2.3 rails_generators/nifty_authentication/templates/authentication.rb
twilson63-nifty-generators-0.2.5 rails_generators/nifty_authentication/templates/authentication.rb
twilson63-nifty-generators-0.2.6 rails_generators/nifty_authentication/templates/authentication.rb
twilson63-nifty-generators-0.2.7 rails_generators/nifty_authentication/templates/authentication.rb
twilson63-nifty-generators-0.2.8 rails_generators/nifty_authentication/templates/authentication.rb
twilson63-nifty-generators-0.2.9 rails_generators/nifty_authentication/templates/authentication.rb
twilson63-nifty-generators-0.3.0 rails_generators/nifty_authentication/templates/authentication.rb
twilson63-nifty-generators-0.3.1 rails_generators/nifty_authentication/templates/authentication.rb
twilson63-nifty-generators-0.3.2 rails_generators/nifty_authentication/templates/authentication.rb
twilson63-nifty-generators-0.3.3 rails_generators/nifty_authentication/templates/authentication.rb
twilson63-nifty-generators-0.3.4 rails_generators/nifty_authentication/templates/authentication.rb
twilson63-nifty-generators-0.3.5 rails_generators/nifty_authentication/templates/authentication.rb
twilson63-nifty-generators-0.3.6 rails_generators/nifty_authentication/templates/authentication.rb
twilson63-nifty-generators-0.3.7 rails_generators/nifty_authentication/templates/authentication.rb
twilson63-nifty-generators-0.3.8 rails_generators/nifty_authentication/templates/authentication.rb
nifty-generators-0.2.2 rails_generators/nifty_authentication/templates/authentication.rb
nifty-generators-0.2.1 rails_generators/nifty_authentication/templates/authentication.rb
nifty-generators-0.2.3 rails_generators/nifty_authentication/templates/authentication.rb