Sha256: 0d338f7ed4f399fcb13e3cc1b08ce268fa75f72bb190dbe26398b7639807d8fa

Contents?: true

Size: 1.03 KB

Versions: 1

Compression:

Stored size: 1.03 KB

Contents

module DoorkeeperHub
  module Helpers
    extend ActiveSupport::Concern

    included do
      before_action :check_login!, :check_d_token
    end

    def check_login!
      redirect_to user_saml_omniauth_authorize_path unless user_signed_in?
    end

    def company
      @company ||=
        current_user.companies.active.find_by(doorkeeper_token: params[:d_token]) ||
          raise(ActionController::RoutingError.new('Not Found'))
    end


    def check_login!
      redirect_to user_saml_omniauth_authorize_path unless user_signed_in?
    end

    def after_sign_in_path_for(current_user)
      root_path(d_token: params_or_default_d_token)
    end

    def default_url_options(options = {})
      options[:d_token] = params[:d_token]
      options
    end

    def check_d_token
      if params[:d_token].nil? && current_user.present?
        redirect_to root_path d_token: params_or_default_d_token
      end
    end

    def params_or_default_d_token
      params[:d_token] || current_user.companies.first.doorkeeper_token
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
doorkeeper_hub-0.1.3 lib/doorkeeper_hub/helpers.rb