skill-assessment-app/app/controllers/application_controller.rb
Mark Moser ace9b864d3 review
2016-07-31 16:34:35 -05:00

32 lines
848 B
Ruby

class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
def current_recruiter
user_parms = { id: session[:user], role: %w(admin recruiter) }
@current_recruiter ||= User.find_by(user_parms) if session[:user]
end
def current_reviewer
user_parms = { id: session[:user], role: %w(admin reviewer) }
@current_reviewer ||= User.find_by(user_parms) if session[:user]
end
def current_candidate
@current_candidate ||= Candidate.find_by(test_hash: session[:test_id]) if session[:test_id]
end
private
def auth_params
params.require(:auth).permit(:email, :password)
end
def authorize_recruiter
redirect_to recruiter_login_path unless current_recruiter
end
def authorize_reviewer
redirect_to review_login_path unless current_reviewer
end
end