Sha256: f7dd247624d181d0bb1cec06a3dd64c01830246ec643f67f6323396166dcca7b

Contents?: true

Size: 799 Bytes

Versions: 4

Compression:

Stored size: 799 Bytes

Contents

module SessionsHelper
  
  def signin(user, remember = false)
    if remember
      cookies.permanent.signed[:remember_token] = [user.id, user.salt]
    else
      cookies.signed[:remember_token] = [user.id, user.salt]
    end
    @current_user = user
  end
    
  def current_user
    @current_user ||= user_from_remember_token
  end
  
  def signed_in?
    current_user.present?
  end
  
  def signout
    cookies.delete(:remember_token)
    @current_user = nil
  end
  
  def authenticate
    redirect_to signin_path, :notice => "Please sign in to access this page." unless signed_in?
  end
  
  private
  
    def user_from_remember_token
      User.authenticate_with_salt(*remember_token)
    end
    
    def remember_token
      cookies.signed[:remember_token] || [nil, nil]
    end
    
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
iceauth-0.0.4 lib/generators/iceauth/templates/app/helpers/sessions_helper.rb
iceauth-0.0.3 lib/generators/iceauth/templates/app/helpers/sessions_helper.rb
iceauth-0.0.2 lib/generators/iceauth/templates/app/helpers/sessions_helper.rb
iceauth-0.0.1 lib/generators/iceauth/templates/app/helpers/sessions_helper.rb