employee->is_logged_in(); return view('home/home'); } /** * Logs the currently logged in employee out of the system. Used in app/Views/partial/header.php * * @return RedirectResponse * @noinspection PhpUnused */ public function getLogout(): RedirectResponse { $this->employee->logout(); return redirect()->to('login'); } /** * Load "change employee password" form * * @return string * @noinspection PhpUnused */ public function getChangePassword(int $employee_id = -1): string // TODO: Replace -1 with a constant { $person_info = $this->employee->get_info($employee_id); foreach (get_object_vars($person_info) as $property => $value) { $person_info->$property = $value; } $data['person_info'] = $person_info; return view('home/form_change_password', $data); } /** * Change employee password * * @return ResponseInterface */ public function postSave(int $employee_id = -1): ResponseInterface // TODO: Replace -1 with a constant { if (!empty($this->request->getPost('current_password')) && $employee_id != -1) { if ($this->employee->check_password($this->request->getPost('username', FILTER_SANITIZE_FULL_SPECIAL_CHARS), $this->request->getPost('current_password'))) { // Validate password length BEFORE hashing $new_password = $this->request->getPost('password'); if (strlen($new_password) < 8) { return $this->response->setJSON([ 'success' => false, 'message' => lang('Employees.password_minlength'), 'id' => -1 ]); } $employee_data = [ 'username' => $this->request->getPost('username', FILTER_SANITIZE_FULL_SPECIAL_CHARS), 'password' => password_hash($new_password, PASSWORD_DEFAULT), 'hash_version' => 2 ]; if ($this->employee->change_password($employee_data, $employee_id)) { return $this->response->setJSON([ 'success' => true, 'message' => lang('Employees.successful_change_password'), 'id' => $employee_id ]); } else { // Failure // TODO: Replace -1 with constant return $this->response->setJSON([ 'success' => false, 'message' => lang('Employees.unsuccessful_change_password'), 'id' => -1 ]); } } else { // TODO: Replace -1 with constant return $this->response->setJSON([ 'success' => false, 'message' => lang('Employees.current_password_invalid'), 'id' => -1 ]); } } else { // TODO: Replace -1 with constant return $this->response->setJSON([ 'success' => false, 'message' => lang('Employees.current_password_invalid'), 'id' => -1 ]); } } }