Sha256: 245905c1d18bee1b2f9ab83c174544cf387ebbc0a6fb934d15c277ee9681b7e0

Contents?: true

Size: 1.25 KB

Versions: 20

Compression:

Stored size: 1.25 KB

Contents

  helper :all
  helper_method :current_user_session, :current_user

  private

    def current_user_session
      return @current_user_session if defined?(@current_user_session)
      @current_user_session = UserSession.find
    end

    def current_user
      return @current_user if defined?(@current_user)
      @current_user = current_user_session && current_user_session.record
    end

    def require_user
      unless current_user
        store_location
        flash[:notice] = 'You must be logged in to access this page'
        redirect_to new_user_session_url
        return false
      end
    end

    def require_no_user
      if current_user
        store_location
        flash[:notice] = 'You must be logged out to access this page'
        redirect_to account_url
        return false
      end
    end

    def require_admin
      unless current_admin && ["admin"].include?(current_admin.role)
        flash[:notice] = "You must be logged in to access this page"
        redirect_to new_admin_login_url
        return false
      end
    end

    def store_location
      session[:return_to] = request.request_uri
    end

    def redirect_back_or_default(default)
      redirect_to(session[:return_to] || default)
      session[:return_to] = nil
    end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
i0n_rails3_generators-0.2.19 lib/generators/authlogic/complete/templates/_application_controller.rb
i0n_rails3_generators-0.2.18 lib/generators/authlogic/complete/templates/_application_controller.rb
i0n_rails3_generators-0.2.17 lib/generators/authlogic/complete/templates/_application_controller.rb
i0n_rails3_generators-0.2.16 lib/generators/authlogic/complete/templates/_application_controller.rb
i0n_rails3_generators-0.2.15 lib/generators/authlogic/complete/templates/_application_controller.rb
i0n_rails3_generators-0.2.14 lib/generators/authlogic/complete/templates/_application_controller.rb
i0n_rails3_generators-0.2.13 lib/generators/authlogic/complete/templates/_application_controller.rb
i0n_rails3_generators-0.2.12 lib/generators/authlogic/complete/templates/_application_controller.rb
i0n_rails3_generators-0.2.11 lib/generators/authlogic/complete/templates/_application_controller.rb
i0n_rails3_generators-0.2.10 lib/generators/authlogic/complete/templates/_application_controller.rb
i0n_rails3_generators-0.2.9 lib/generators/authlogic/complete/templates/_application_controller.rb
i0n_rails3_generators-0.2.8 lib/generators/authlogic/complete/templates/_application_controller.rb
i0n_rails3_generators-0.2.7 lib/generators/authlogic/complete/templates/_application_controller.rb
i0n_rails3_generators-0.2.6 lib/generators/authlogic/complete/templates/_application_controller.rb
i0n_rails3_generators-0.2.5 lib/generators/authlogic/complete/templates/_application_controller.rb
i0n_rails3_generators-0.2.4 lib/generators/authlogic/complete/templates/_application_controller.rb
i0n_rails3_generators-0.2.3 lib/generators/authlogic/complete/templates/_application_controller.rb
i0n_rails3_generators-0.2.2 lib/generators/authlogic/complete/templates/_application_controller.rb
i0n_rails3_generators-0.2.1 lib/generators/authlogic/complete/templates/_application_controller.rb
i0n_rails3_generators-0.2.0 lib/generators/authlogic/complete/templates/_application_controller.rb