candidate login/logout
This commit is contained in:
		@@ -1,3 +1,7 @@
 | 
			
		||||
class ApplicationController < ActionController::Base
 | 
			
		||||
  protect_from_forgery with: :exception
 | 
			
		||||
 | 
			
		||||
  def current_candidate
 | 
			
		||||
    @current_candidate ||= Candidate.find_by(test_hash: session[:test_id])
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 
 | 
			
		||||
@@ -26,14 +26,24 @@ class CandidateController < ApplicationController
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def thankyou
 | 
			
		||||
    redirect_to root_path if session[:test_id].nil?
 | 
			
		||||
    reset_session
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def saved
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def validate
 | 
			
		||||
    candidate = Candidate.find_by(test_hash: params['test_id'])
 | 
			
		||||
 | 
			
		||||
    if candidate.nil?
 | 
			
		||||
      reset_session
 | 
			
		||||
      redirect_to root_path, alert: "Sorry, incorrect test id"
 | 
			
		||||
    else
 | 
			
		||||
      session[:test_id] = candidate.test_hash
 | 
			
		||||
      redirect_to :question
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def live_coder
 | 
			
		||||
    @question = Question.find(params[:question_id])
 | 
			
		||||
@@ -41,9 +51,9 @@ class CandidateController < ApplicationController
 | 
			
		||||
    render layout: false
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  # private
 | 
			
		||||
  #
 | 
			
		||||
  #   def question_params
 | 
			
		||||
  #     params.permit(:save)
 | 
			
		||||
  #   end
 | 
			
		||||
  private
 | 
			
		||||
 | 
			
		||||
    def question_params
 | 
			
		||||
      params.permit(:save)
 | 
			
		||||
    end
 | 
			
		||||
end
 | 
			
		||||
 
 | 
			
		||||
@@ -1,8 +1,8 @@
 | 
			
		||||
<% content_for :title, "Skills Assessment" %>
 | 
			
		||||
 | 
			
		||||
<!-- if (isset($_SESSION['candidateId'])) { ?> -->
 | 
			
		||||
<% if session[:test_id].present? %>
 | 
			
		||||
 | 
			
		||||
<main class="intro_tpl">
 | 
			
		||||
  <main class="intro_tpl">
 | 
			
		||||
    <h1 class="prft-heading">Oops!</h1>
 | 
			
		||||
    <p>
 | 
			
		||||
      Looks like you hit the browser's Back button. You can't go backwards in the test,
 | 
			
		||||
@@ -10,11 +10,11 @@
 | 
			
		||||
    </p>
 | 
			
		||||
 | 
			
		||||
    <a href="<%= question_path %>"><button>Continue Test</button></a>
 | 
			
		||||
</main>
 | 
			
		||||
  </main>
 | 
			
		||||
 | 
			
		||||
<!-- <?php } else { ?> -->
 | 
			
		||||
<% else %>
 | 
			
		||||
 | 
			
		||||
<main class="intro_tpl">
 | 
			
		||||
  <main class="intro_tpl">
 | 
			
		||||
    <h1 class="prft-heading">Let's Get Started</h1>
 | 
			
		||||
    <p>
 | 
			
		||||
      This is a skills assessment test. It's the first step in the process of interviewing
 | 
			
		||||
@@ -37,8 +37,10 @@
 | 
			
		||||
    <%= form_tag(validate_candidate_path) do %>
 | 
			
		||||
      <div class="form-group">
 | 
			
		||||
        <label for="userid">What's your User ID?</label>
 | 
			
		||||
      <input type="text" id="userId" name="userId" required/>
 | 
			
		||||
        <input type="text" id="test_id" name="test_id" required/>
 | 
			
		||||
      </div>
 | 
			
		||||
      <button type="submit">Begin</button>
 | 
			
		||||
    <% end %>
 | 
			
		||||
</main>
 | 
			
		||||
  </main>
 | 
			
		||||
 | 
			
		||||
<% end %>
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user