public static function createUser()
 {
     $app = \Slim\Slim::getInstance();
     //$jsonData = $app->request->getBody();
     //$allPostVars = json_decode($jsonData,true);
     $allPostVars = $app->request->post();
     $name = @$allPostVars['name'] ? @trim(htmlspecialchars($allPostVars['name'], ENT_QUOTES, 'UTF-8')) : NULL;
     $email = @$allPostVars['email'] ? @trim(htmlspecialchars($allPostVars['email'], ENT_QUOTES, 'UTF-8')) : NULL;
     $password = @$allPostVars['password'] ? @trim($allPostVars['password']) : NULL;
     $cfmpassword = @$allPostVars['confirm-password'] ? @trim($allPostVars['confirm-password']) : NULL;
     if ($password !== $cfmpassword || !InputValidator::isValidStringInput($name, 255, 0) || !InputValidator::isValidStringInput($email, 255, 0) || !InputValidator::isValidEmail($email) || !InputValidator::isValidStringInput($password, 60, 8)) {
         $app->render(400, ['Status' => 'Invalid input.']);
         return;
     }
     try {
         $userExists = \parser\models\User::where('email', '=', $email)->first();
         if ($userExists) {
             $app->render(400, ['Status' => 'A user with that email exists already.']);
         } else {
             $user = new \parser\models\User();
             $user->name = $name;
             $user->email = $email;
             $user->password = md5($password);
             $user->save();
             echo json_encode($user, JSON_UNESCAPED_SLASHES);
         }
     } catch (\Exception $e) {
         $app->render(500, ['Status' => 'An error occurred.']);
     }
 }
 public static function applyForJob($job_id)
 {
     $app = \Slim\Slim::getInstance();
     if (!\parser\controllers\ApplicationController::isLogin()) {
         $app->render(401, ['Status' => 'Unauthorised.']);
         return;
     }
     try {
         $allPostVars = $app->request->post();
         $resume_path = \parser\controllers\ApplicationController::saveResumeFromUpload();
         $telephone = @$allPostVars['telephone'] ? @trim(htmlspecialchars($allPostVars['telephone'], ENT_QUOTES, 'UTF-8')) : NULL;
         if (!InputValidator::isValidStringInput($telephone, 10, 8) || !preg_match("/^[0-9]{8,10}\$/", $telephone)) {
             $app->render(400, ['Status' => 'Invalid input.']);
             return;
         }
         $job = \parser\models\Job::where('id', '=', $job_id)->first();
         $user = \parser\models\User::where('email', '=', $_SESSION['email'])->first();
         $job_application = \parser\models\Application::where('job_id', '=', $job->id)->where('user_id', '=', $user->id)->first();
         if ($user && $job && !$job_application) {
             $job_application = new \parser\models\Application();
             $job_application->user_id = $user->id;
             $job_application->job_id = $job->id;
             $job_application->contact = $telephone;
             $job_application->resume_path = $resume_path;
             $job_application->save();
             shell_exec("/usr/bin/java -jar ../../parser.jar './resume-uploads/{$resume_path}' '{$user->id}' '{$job->id}' '{$job_application->id}' >/dev/null 2>/dev/null &");
             echo json_encode($job_application, JSON_UNESCAPED_SLASHES);
         } else {
             throw new \Exception('Error!');
         }
     } catch (\Exception $e) {
         $app->render(500, ['Status' => 'An error occurred.']);
     }
 }
 public static function addRequirementsToJob($job_id)
 {
     $app = \Slim\Slim::getInstance();
     if (!\parser\controllers\ApplicationController::isLogin()) {
         $app->render(401, ['Status' => 'Unauthorised.']);
         return;
     }
     $allPostVars = $app->request->post();
     $keyword = @$allPostVars['keyword'] ? @trim(htmlspecialchars($allPostVars['keyword'], ENT_QUOTES, 'UTF-8')) : NULL;
     $weightage = isset($allPostVars['weightage']) ? @floatval($allPostVars['weightage']) : NULL;
     $is_required = @$allPostVars['is_required'] === "on" ? true : false;
     $is_available = @$allPostVars['is_available'] === "on" ? true : false;
     if (!preg_match('/^\\d+(.\\d{1,2})?$/', $weightage) || !InputValidator::isValidStringInput($keyword, 255, 0)) {
         $app->render(400, ['Status' => 'Invalid input.']);
         return;
     }
     try {
         $user = \parser\models\User::where('email', '=', $_SESSION['email'])->first();
         $job = \parser\models\Job::where('id', '=', $job_id)->whereIn('id', function ($query) use($user) {
             $query->select('job_id')->from('job_recruiters')->where('user_id', '=', $user->id);
         })->first();
         if ($user && $job) {
             $keyword = \parser\models\Keyword::firstOrCreate(array('keyword' => $keyword));
             $requirement = new \parser\models\JobRequirement();
             $requirement->job_id = $job->id;
             $requirement->keyword_id = $keyword->id;
             $requirement->weightage = $weightage;
             $requirement->is_required = $is_required;
             $requirement->is_available = $is_available;
             $requirement->save();
             echo json_encode($requirement, JSON_UNESCAPED_SLASHES);
         } else {
             $app->render(401, ['Status' => 'Unauthorised.']);
             return;
         }
     } catch (\Exception $e) {
         $app->render(500, ['Status' => 'An error occurred.']);
         return;
     }
 }