2017-01-17 1 views
0

現在、私のプロジェクトではdelayed-webという宝石を使用しています。私は複数のユーザーの役割を持っている、と私はユーザーの役割を販売したいとは思わないWebページの遅延インターフェイスにアクセスすることができますインターフェイス。私はすでにアプリケーションコントローラの認証をチェックする方法を持っています。しかし、私はルートファイルでそれを動作させる方法を知らない。どんな提案もありがとうございます。遅延ウェブ宝石のカスタム認証チェック?

:Devise gemを使用していません。私は自分の認証をロールバックします。

application_controller.rb

class ApplicationController < ActionController::Base 
    # Prevent CSRF attacks by raising an exception. 
    # For APIs, you may want to use :null_session instead. 
    protect_from_forgery with: :exception 

    before_action :authenticate 
    before_action :check_pricer_role, except: [:export_for_customer] 
    helper_method :check_pricer_role 
def check_pricer_role 
    unless current_user && (current_user.pricer? || current_user.admin?) 
     redirect_to errors_not_found_path 
    end 
    end 
end 

routes.rbを

Rails.application.routes.draw do 
    # How to apply the defined authentication here? 
    mount Delayed::Web::Engine, at: '/jobs' 
end 
+0

あなたは 'Devise'宝石やその他を使用していますか? –

+0

@AlexKojinありがとうございますが、プロジェクトでDevise宝石を使用していません。 –

+0

ユーザーを認証する方法は?セッションごとに?詳細を知ることが重要です –

答えて

0

[OK]を、私は問題を解決してきました。 Requestオブジェクトの内部に保存されている認証トークンに基づいて現在のユーザーを見つけることができます(もう一度、認証用の宝石は使用しません。自分のロールをロールしますが、とにかくここの問題)。 これは完全なソリューションである、誰かが道同じ困難に遭遇した場合に:

class AuthConstraint 
     def matches?(request) 
     current_user ||= User.find_by_auth_token(request.cookie_jar['auth_token']) if request.cookie_jar['auth_token'] 
     current_user.present? && !current_user.sales? 
     end 
    end 

    Rails.application.routes.draw do 
     mount Delayed::Web::Engine, at: '/jobs', :constraints => AuthConstraint.new 
     //Other resources ........ 
    end