<commit_before><?php

class SessionsController extends \BaseController {

  protected $sessionsValidator;

  public function __construct(UserSessionValidator $userSessionValidator, AdminSessionValidator $adminSessionValidator)
  {
    $this->userSessionValidator = $userSessionValidator;
    $this->adminSessionValidator = $adminSessionValidator;
  }


  /**
   * Show the form for creating a new resource.
   * GET /sessions/create
   *
   * @return Response
   */
  public function create()
  {
    $type = get_login_type();

    return View::make('sessions.create', compact('type'));
  }

  /**
   * Allows an admin to log in.
   *
   */
  public function adminCreate()
  {
    $type = 'admin';
    return View::make('sessions.create', compact('type'));
  }

  /**
   * Store a newly created resource in storage.
   * POST /sessions
   *
   * @return Response
   */
  public function store()
  {
    // If coming from admin, use that login method.
    if (Input::has('password')) {
      $input = Input::only('email', 'password');
      $this->adminSessionValidator->validate($input);
      return $this->adminLogin($input);
    }
    // Use the user login/create method.
    else {
      $input = Input::only('first_name', 'email', 'phone', 'birthdate', 'candidate_id');
      $this->userSessionValidator->validate($input);
      return $this->userLogin($input);
    }

  }
<commit_msg>Redirect to candidate page on failed validation. Fixes #157.<commit_after><?php

class SessionsController extends \BaseController {

  protected $sessionsValidator;

  public function __construct(UserSessionValidator $userSessionValidator, AdminSessionValidator $adminSessionValidator)
  {
    $this->userSessionValidator = $userSessionValidator;
    $this->adminSessionValidator = $adminSessionValidator;
  }


  /**
   * Show the form for creating a new resource.
   * GET /sessions/create
   *
   * @return Response
   */
  public function create()
  {
    $type = get_login_type();

    return View::make('sessions.create', compact('type'));
  }

  /**
   * Allows an admin to log in.
   *
   */
  public function adminCreate()
  {
    $type = 'admin';
    return View::make('sessions.create', compact('type'));
  }

  /**
   * Store a newly created resource in storage.
   * POST /sessions
   *
   * @return Response
   */
  public function store()
  {
    // If coming from admin, use that login method.
    if (Input::has('password')) {
      $input = Input::only('email', 'password');
      $this->adminSessionValidator->validate($input);
      return $this->adminLogin($input);
    }
    // Use the user login/create method.
    else {
      $input = Input::only('first_name', 'email', 'phone', 'birthdate', 'candidate_id');

      try {
        $this->userSessionValidator->validate($input);
      } catch(Laracasts\Validation\FormValidationException $exception) {
        // If there is a form validation error, show form errors on candidate page.
        $candidate = Candidate::find($input['candidate_id']);
        return Redirect::route('candidates.show', [$candidate->slug])->withInput()
          ->withErrors($exception->getErrors())
          ->withFlashMessage('There were some problems with that submission. Try again!')
          ->with('flash_message_type', 'error');
      }

      return $this->userLogin($input);
    }

  }

{'fraction_non_alphanumeric': 0.1377245508982036, 'fraction_numerical': 0.0008982035928143712, 'mean_word_length': 3.2131147540983607, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3383884', 'n_tokens_mistral': 965, 'n_tokens_neox': 938, 'n_words': 233}