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 updateSettingsForJob($job_id) { $app = \Slim\Slim::getInstance(); if (!\parser\controllers\ApplicationController::isLogin()) { $app->render(401, ['Status' => 'Unauthorised.']); return; } $allPostVars = $app->request->post(); $minimum_score = @$allPostVars['minimum_score'] ? @intval($allPostVars['minimum_score']) : 0; $is_available = @$allPostVars['is_available'] ? @$allPostVars['is_available'] : 0; $is_available = $is_available == "on" ? 1 : 0; if (!preg_match('/^\\d+$/', $minimum_score)) { $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) { $job->minimum = $minimum_score; $job->is_available = $is_available; $job->save(); echo json_encode($job, JSON_UNESCAPED_SLASHES); } else { $app->render(401, ['Status' => 'Unauthorised.']); return; } } catch (\Exception $e) { $app->render(500, ['Status' => 'An error occurred.']); return; } }