public function execute() { $httpContext = new \Framework\Core\HttpContext(); try { $isInRole = Identity::isUserInRole($httpContext->identity()->username, \Framework\Config\Config::USER_ROLES[0]); if (!Identity::isUserLogged() || !$isInRole) { $root = $_SERVER['DOCUMENT_ROOT'] . $_SERVER['SCRIPT_NAME']; header("Location: {$root}", 302); } } catch (\Exception $e) { $root = $_SERVER['DOCUMENT_ROOT'] . $_SERVER['SCRIPT_NAME']; header("Location: {$root}", 302); } }
/** * @OnlyAnonymous */ public function postLogin(AdminLoginBindingModel $userModel) : View { try { if (!$userModel->isValid()) { $viewModel = new \Framework\Areas\Admin\ViewModels\Login\GetLoginViewModel(); $viewModel->errorsList = $userModel->getErrorsList(); $viewModel->error = true; return new View('\\Login\\getLogin', $viewModel); } $result = \Framework\Core\Identity::login($userModel->username, $userModel->password); if (!\Framework\Core\Identity::isUserInRole($userModel->username, \Framework\Config\Config::USER_ROLES[0])) { throw new \Exception("Invalid administrator credentials"); } $this->redirect("../admin"); } catch (\Exception $e) { $viewModel = new \Framework\Areas\Admin\ViewModels\Login\GetLoginViewModel(); $viewModel->errorsList = $userModel->getErrorsList(); $viewModel->errorsList[] = $e->getMessage(); $viewModel->error = true; return new View('\\Login\\getLogin', $viewModel); } }
public function execute() { $role = $this->annotationValue; $httpContext = new \Framework\Core\HttpContext(); if (!isset($role) || trim($role) == "" || $role === true) { if (!Identity::isUserLogged()) { $root = $_SERVER['DOCUMENT_ROOT'] . $_SERVER['SCRIPT_NAME']; header("Location: {$root}", 302); } } else { try { $isInRole = Identity::isUserInRole($httpContext->identity()->username, $role); if (!Identity::isUserLogged() || !$isInRole) { $root = $_SERVER['DOCUMENT_ROOT'] . $_SERVER['SCRIPT_NAME']; header("Location: {$root}", 302); } } catch (\Exception $e) { $root = $_SERVER['DOCUMENT_ROOT'] . $_SERVER['SCRIPT_NAME']; header("Location: {$root}", 302); } } }