コード例 #1
0
ファイル: Admin.php プロジェクト: pgyordanov/PHP
 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);
     }
 }
コード例 #2
0
ファイル: LoginController.php プロジェクト: pgyordanov/PHP
 /**
  * @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);
     }
 }
コード例 #3
0
ファイル: Authorize.php プロジェクト: pgyordanov/PHP
 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);
         }
     }
 }