<commit_before><?hh

class AcceptInviteController extends BaseController {
  public static function getPath(): string {
    return '/invite/accept';
  }

  public static function getConfig(): ControllerConfig {
    return
      (new ControllerConfig())
        ->addCheck(Auth::requireLogin())
        ->addCheck(Auth::requireState(Vector {UserState::Accepted}));
  }

  public static function get(): :xhp {
    return <nucleus:accept-invite user={Session::getUser()} />;
  }

  public static function post(): void {
    $user = Session::getUser();

    // The user has denied their invite
    if (isset($_POST['deny'])) {
      UserMutator::update($user->getID())
        ->setState(UserState::Rejected)
        ->save();
      Flash::set(
        Flash::SUCCESS,
        "Your invitation was successfully declined.",
      );
      Route::redirect(DashboardController::getPath());
    }

    // An accept wasn't sent, error
    if (!isset($_POST['accept'])) {
      http_response_code(400);
      Flash::set(Flash::SUCCESS, "Something went wrong, please try again");
      Route::redirect(self::getPath());
    }

    // Make sure the Code of Conduct is accepted
    if (!isset($_POST['coc'])) {
      Flash::set(
        Flash::ERROR,
        "The MLH Code of Conduct must be accepted before you can confirm your invitation",
      );
      Route::redirect(self::getPath());
    }

    // The user is uploading a resume
    if ($_FILES['resume']['name'] !== "") {
      // Make sure the resume is a PDF
      $file_type =
        pathinfo(basename($_FILES["resume"]["name"]), PATHINFO_EXTENSION);
      if ($file_type != "pdf") {
        http_response_code(400);
        Flash::set(Flash::ERROR, "Résumé must be in pdf format");
        Route::redirect(self::getPath());
      }

      $upload_dir = "uploads/".$user->getID();

      // Create the upload directory for the user
      if (!file_exists($upload_dir)) {
        mkdir($upload_dir);
      }

      // Move the file to its final home
      if (!move_uploaded_file(
            $_FILES['resume']['tmp_name'],
            $upload_dir."/resume.pdf",
          )) {
        Flash::set(Flash::ERROR, "Résumé was not uploaded successfully");
        Route::redirect(self::getPath());
      }
    }

    // Get the demographic information
    $data = Map {
      'gender' => $user->getGender(),
      'school' => $user->getSchool(),
      'major' => $user->getMajor(),
    };

    if (isset($_POST['first-hackathon']) &&
        $_POST['first-hackathon'] !== "optout") {
      $data['is_first_hackathon'] =
        $_POST['first-hackathon'] === "yes" ? true : false;
    }

    if (isset($_POST['year'])) {
      if ($_POST['year'] !== "Select one") {
        $data['year'] = $_POST['year'];
      }
    }

    if (isset($_POST['race'])) {
      $races = Vector {};
      foreach ($_POST['race'] as $race) {
        if ($race === "other") {
          $races[] = $_POST['otherrace'];
          continue;
        }
        $races[] = $race;
      }

      $data['race'] = $races;
    }

    // Send demographic information to keen
    $client = KeenIO\Client\KeenIOClient::factory(
      [
        'projectId' => Config::get('Keen')['project_id'],
        'writeKey' => Config::get('Keen')['write_key'],
        'readKey' => Config::get('Keen')['read_key'],
      ],
    );
    $client->addEvent('confirmation', $data->toArray());

    // Set the user to confirmed
    UserMutator::update($user->getID())
      ->setState(UserState::Confirmed)
      ->save();
    Flash::set(Flash::SUCCESS, "You've successfully confirmed.");
    Route::redirect(DashboardController::getPath());
  }
}<commit_msg>Work towards moving away from $_POST<commit_after><?hh

class AcceptInviteController extends BaseController {
  public static function getPath(): string {
    return '/invite/accept';
  }

  public static function getConfig(): ControllerConfig {
    return
      (new ControllerConfig())
        ->addCheck(Auth::requireLogin())
        ->addCheck(Auth::requireState(Vector {UserState::Accepted}));
  }

  public static function get(): :xhp {
    return <nucleus:accept-invite user={Session::getUser()} />;
  }

  public static function post(): void {
    $user = Session::getUser();
    $post_params = getPOSTParams();

    // The user has denied their invite
    if (idx($post_params, 'deny', false)) {
      UserMutator::update($user->getID())
        ->setState(UserState::Rejected)
        ->save();
      Flash::set(
        Flash::SUCCESS,
        "Your invitation was successfully declined.",
      );
      Route::redirect(DashboardController::getPath());
    }

    // An accept wasn't sent, error
    if (!idx($post_params, 'accept', false)) {
      http_response_code(400);
      Flash::set(Flash::SUCCESS, "Something went wrong, please try again");
      Route::redirect(self::getPath());
    }

    // Make sure the Code of Conduct is accepted
    if (!array_key_exists('coc', $post_params)) {
      Flash::set(
        Flash::ERROR,
        "The MLH Code of Conduct must be accepted before you can confirm your invitation",
      );
      Route::redirect(self::getPath());
    }

    // The user is uploading a resume
    if ($_FILES['resume']['name'] !== "") {
      // Make sure the resume is a PDF
      $file_type =
        pathinfo(basename($_FILES["resume"]["name"]), PATHINFO_EXTENSION);
      if ($file_type != "pdf") {
        http_response_code(400);
        Flash::set(Flash::ERROR, "Résumé must be in pdf format");
        Route::redirect(self::getPath());
      }

      $upload_dir = "uploads/".$user->getID();

      // Create the upload directory for the user
      if (!file_exists($upload_dir)) {
        mkdir($upload_dir);
      }

      // Move the file to its final home
      if (!move_uploaded_file(
            $_FILES['resume']['tmp_name'],
            $upload_dir."/resume.pdf",
          )) {
        Flash::set(Flash::ERROR, "Résumé was not uploaded successfully");
        Route::redirect(self::getPath());
      }
    }

    // Get the demographic information
    $data = Map {
      'gender' => $user->getGender(),
      'school' => $user->getSchool(),
      'major' => $user->getMajor(),
    };

    if (isset($_POST['first-hackathon']) &&
        $_POST['first-hackathon'] !== "optout") {
      $data['is_first_hackathon'] =
        $_POST['first-hackathon'] === "yes" ? true : false;
    }

    if (array_key_exists('year', $post_params)) {
      if ($_POST['year'] !== "Select one") {
        $data['year'] = $_POST['year'];
      }
    }

    if (array_key_exists('race', $post_params)) {
      $races = Vector {};
      foreach ($_POST['race'] as $race) {
        if ($race === "other") {
          $races[] = $_POST['otherrace'];
          continue;
        }
        $races[] = $race;
      }

      $data['race'] = $races;
    }

    // Send demographic information to keen
    $client = KeenIO\Client\KeenIOClient::factory(
      [
        'projectId' => Config::get('Keen')['project_id'],
        'writeKey' => Config::get('Keen')['write_key'],
        'readKey' => Config::get('Keen')['read_key'],
      ],
    );
    $client->addEvent('confirmation', $data->toArray());

    // Set the user to confirmed
    UserMutator::update($user->getID())
      ->setState(UserState::Confirmed)
      ->save();

    Flash::set(Flash::SUCCESS, "You've successfully confirmed.");
    Route::redirect(DashboardController::getPath());
  }
}
{'fraction_non_alphanumeric': 0.1731002017484869, 'fraction_numerical': 0.0016139878950907868, 'mean_word_length': 2.697662854301343, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 45, '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': '6800150', 'n_tokens_mistral': 2290, 'n_tokens_neox': 2205, 'n_words': 484}