skill-assessment-app/app/controllers/recruiter_controller.rb

53 lines
1.3 KiB
Ruby
Raw Normal View History

2016-07-31 09:56:02 -05:00
class RecruiterController < ApplicationController
before_action :authorize_recruiter, except: [:login, :auth]
def index
@candidates = current_recruiter.candidates
end
def new
@candidate = Candidate.new
2016-07-31 14:47:15 -05:00
render :form
2016-07-31 09:56:02 -05:00
end
def create
2016-07-31 14:47:15 -05:00
@candidate = Candidate.create(candidate_params.merge(recruiter_id: current_recruiter.id))
if @candidate.persisted?
2016-08-02 11:48:18 -05:00
CandidateMailer.welcome(@candidate).deliver_now
RecruiterMailer.candidate_created(@candidate).deliver_now
2016-07-31 14:47:15 -05:00
redirect_to recruiter_path, flash: { notice: "Sucessfully created candidate #{@candidate.name}" }
else
2016-08-04 08:51:54 -05:00
flash[:error] = "Failed to save candidate."
2016-07-31 14:47:15 -05:00
render :form
end
2016-07-31 09:56:02 -05:00
end
def login
redirect_to recruiter_path unless current_recruiter.nil?
end
def auth
2016-07-31 16:34:35 -05:00
recruiter = User.find_by(email: auth_params[:email], role: %w(admin recruiter))
2016-07-31 09:56:02 -05:00
if recruiter && recruiter.authenticate(auth_params[:password])
session[:user] = recruiter.to_i
redirect_to recruiter_path
else
2016-08-04 17:24:53 -05:00
redirect_to recruiter_login_path,
flash: { error: "Sorry, incorrect email or password. Please try again." }
2016-07-31 09:56:02 -05:00
end
end
def logout
reset_session
redirect_to recruiter_login_path
end
private
def candidate_params
params.require(:candidate).permit(:name, :email, :experience, :quiz_id)
end
end