Sha256: b7fd0246e03076b49ebf893088c2394a2effcb7ebf7bde1d0d5ec1b4455839c0

Contents?: true

Size: 710 Bytes

Versions: 4

Compression:

Stored size: 710 Bytes

Contents

# frozen_string_literal: true

module Tramway
  module AuthManagement
    def sign_in(user)
      session[:user_id] = user.id
    end

    def sign_out
      session[:user_id] = nil
    end

    def signed_in?
      current_user
    end

    def authenticate_user!
      redirect_to new_session_path unless signed_in?
    end

    def authenticate_admin!
      if signed_in?
        if !current_user.admin? && request.env['PATH_INFO'] != ::Tramway::Auth.root_path
          redirect_to ::Tramway::Auth.root_path
        end
      else
        redirect_to '/auth/session/new'
      end
    end

    def current_user
      @_current_user ||= ::Tramway::User::User.find_by id: session[:user_id]
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
tramway-auth-1.2.1.1 app/controllers/concerns/tramway/auth_management.rb
tramway-auth-1.2.1 app/controllers/concerns/tramway/auth_management.rb
tramway-auth-1.2 app/controllers/concerns/tramway/auth_management.rb
tramway-auth-1.1.0.3 app/controllers/concerns/tramway/auth_management.rb