public function actionAuthentication() { if (!empty($_POST['username']) && !empty($_POST['password'])) { try { $condition = []; $condition['username'] = $_POST['username']; $condition['password'] = $_POST['password']; $condition['status'] = 1; $user = User::findByCondition($condition)[0]; Application::setCurrentByKey(['username' => $user->getUsername(), 'role' => $user->getUserRole()]); $logger = new Logger(); $logger->info('SUCCESSFUL LOGIN', ['code' => 100, 'info' => $condition]); setcookie('lastuser', $user->getUserName(), time() + 86400, '/'); setcookie('lastdate', time(), time() + 86400, '/'); header('Location: /'); } catch (E404Exception $e) { Application::catchException($e); } } else { $logger = new Logger(); $logger->notice('empty field exists!', ['code' => 101, 'info' => $_POST]); $_SESSION['notice'] = 'empty field exists!'; header('Location: /auth/login'); } }
$action = 'login'; } else { switch (true) { case !empty($urlParts): Application::setCurrentByKey(['pageid' => array_shift($urlParts)]); break; case !empty($_POST['id']): Application::setCurrentByKey(['pageid' => $_POST['id']]); break; case empty($control): Application::unsetCurrentByKey('pageid'); break; default: break; } } /************** call Controller's Method ******************************/ $ctrl = $control ?: 'show'; $ctrlClassName = 'App\\Controllers\\' . ucfirst($ctrl); $act = $action ?: 'all'; $method = 'action' . ucfirst($act); try { $controller = new $ctrlClassName(); $controller->{$method}(); } catch (E403Exception $e) { Application::catchException($e); } catch (E404Exception $e) { Application::catchException($e); } catch (E405Exception $e) { Application::catchException($e); }