Пример #1
0
 public function index()
 {
     $user = UserService::getCurrentUser();
     if (isset($user)) {
         echo 'Welcome, ' . $user->getNickname();
         if (UserService::isCurrentUserAdmin()) {
             $data = array('title' => 'Admin Section', 'hello' => 'Hello admin...', 'content' => 'You are accessing the backend now');
             $this->render("admin.html", $data);
         } else {
             header('Location: ' . UserService::createLoginURL($_SERVER['REQUEST_URI']));
         }
     }
 }
Пример #2
0
 public function __construct()
 {
     $this->user = UserService::getCurrentUser();
     $this->is_admin = UserService::isCurrentUserAdmin();
 }
Пример #3
0
 public function testIsCurrentUserAdmin()
 {
     putenv('USER_IS_ADMIN=0');
     $this->assertFalse(UserService::isCurrentUserAdmin());
     putenv('USER_IS_ADMIN=1');
     $this->assertTrue(UserService::isCurrentUserAdmin());
 }
 /**
  * @dataProvider isCurrentUserAdminDataProvider
  */
 public function testIsCurrentUserAdmin($env_var_name)
 {
     putenv($env_var_name . '=0');
     $this->assertFalse(UserService::isCurrentUserAdmin());
     putenv($env_var_name . '=1');
     $this->assertTrue(UserService::isCurrentUserAdmin());
     // Clear the environment variable.
     putenv($env_var_name);
 }