Sha256: 544cb3a626a4927a711c469e7aacb8818bdc01a6c31191da01c8eee61e2cd1f8

Contents?: true

Size: 1.07 KB

Versions: 5

Compression:

Stored size: 1.07 KB

Contents

class ApplicationController < ActionController::Base

  protect_from_forgery

  helper_method :user
  helper_method :authenticated?

private

  def user
    cookie = cookies.signed[:user]
    @_user ||= User.find(cookie) rescue deauthenticate if cookie
  end

  def authenticate(user)
    cookies.permanent.signed[:user] = user.id
  end

  def deauthenticate
    cookies.delete :user
  end

  def authenticated?
    user.present?
  end

  def authenticate!
    unless authenticated?
      store
      flash[:warning] = 'You must be logged in.'
      respond_to do |format|
        format.html { redirect_to new_user_path }
      end
      return false
    end
  end

  def deauthenticate!
    if authenticated?
      store
      flash[:warning] = 'You must be logged out.'
      respond_to do |format|
        format.html { redirect_to edit_user_path }
      end
      return false
    end
  end

  def store
    session[:location] = request.fullpath
  end

  def restore(options)
    location = session[:location] || options[:default]
    session[:location] = nil
    return location
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
formula-1.0.0 test/dummy/app/controllers/application_controller.rb
formula-0.3.9 test/dummy/app/controllers/application_controller.rb
formula-0.3.8 test/dummy/app/controllers/application_controller.rb
formula-0.3.7 test/dummy/app/controllers/application_controller.rb
formula-0.3.6 test/dummy/app/controllers/application_controller.rb