2016-09-08 10:25:33 -05:00
|
|
|
# frozen_string_literal: true
|
2016-07-27 22:16:12 -05:00
|
|
|
class CandidateController < ApplicationController
|
2016-08-02 18:02:20 -05:00
|
|
|
before_action :authorize_candidate, except: [:login, :validate, :live_coder]
|
|
|
|
before_action :send_to_oops, only: [:login]
|
|
|
|
|
|
|
|
def login
|
|
|
|
login_candidate
|
|
|
|
redirect_to :thankyou and return if current_candidate && current_candidate.completed?
|
|
|
|
redirect_to :welcome if current_candidate
|
|
|
|
|
|
|
|
flash[:error] = "Sorry, incorrect test id" if params[:test_hash].present?
|
|
|
|
end
|
2016-07-31 18:54:12 -05:00
|
|
|
|
2016-07-27 22:16:12 -05:00
|
|
|
def welcome
|
2016-08-02 18:30:15 -05:00
|
|
|
render :welcome_back if current_candidate.answers.count > 0
|
2016-07-27 22:16:12 -05:00
|
|
|
end
|
|
|
|
|
2016-07-31 18:54:12 -05:00
|
|
|
def saved
|
|
|
|
end
|
|
|
|
|
2016-08-02 18:02:20 -05:00
|
|
|
def oops
|
|
|
|
end
|
|
|
|
|
2016-07-31 18:54:12 -05:00
|
|
|
def thankyou
|
|
|
|
redirect_to root_path if session[:test_id].nil?
|
|
|
|
reset_session
|
|
|
|
end
|
|
|
|
|
|
|
|
def validate
|
|
|
|
candidate = Candidate.find_by(test_hash: params['test_id'])
|
2016-08-01 16:43:05 -05:00
|
|
|
redirect_to(root_path, flash: { error: "Sorry, incorrect test id" }) and return if candidate.nil?
|
2016-07-31 18:54:12 -05:00
|
|
|
|
|
|
|
session[:test_id] = candidate.test_hash
|
|
|
|
redirect_to :thankyou and return if candidate.completed?
|
2016-08-02 18:02:20 -05:00
|
|
|
redirect_to :welcome
|
2016-07-29 11:00:04 -05:00
|
|
|
end
|
|
|
|
|
2016-07-29 11:53:01 -05:00
|
|
|
private
|
|
|
|
|
2016-08-02 18:02:20 -05:00
|
|
|
def login_candidate
|
|
|
|
candidate = Candidate.find_by(test_hash: params['test_id'])
|
|
|
|
return false if candidate.nil?
|
|
|
|
|
|
|
|
session[:test_id] = candidate.test_hash
|
|
|
|
end
|
|
|
|
|
|
|
|
def send_to_oops
|
|
|
|
redirect_to oops_path if current_candidate
|
|
|
|
end
|
2016-07-27 22:16:12 -05:00
|
|
|
end
|