/**
  * Check to see if a user is in a group
  *
  * @param integer $userId User ID
  * @param integer $groupId Group ID
  * @param OutputInterface $output Output object
  */
 public function inGroup($userId, $groupId, $output)
 {
     $group = Gatekeeper::findGroupById($groupId);
     $result = Gatekeeper::findUserById($userId)->inGroup($groupId);
     $output->writeln($result === true ? "User in group '" . $group->description . "'." : "User <options=bold>not</options=bold> in group '" . $group->description . "'.");
     return $result;
 }
 /**
  * Fetch the user by the value of the "remember" me token
  *
  * @param string $identifier User identifier
  * @param string $token Token value
  * @return \Illuminate\Contracts\Auth\Authenticatable|null
  */
 public function retrieveByToken($identifier, $token)
 {
     $user = is_int($identifier) ? Gatekeeper::findUserById($identifier) : Gatekeeper::findUserByUsername($identifier);
     $tokens = $user->authTokens;
     if ($user === false || isset($tokens[0]) && $tokens[0]->token !== $token) {
         return null;
     }
     return new UserAuthenticatable($user);
 }
Exemple #3
0
 public function loadPost($id)
 {
     $stmt = $this->pdo->prepare("SELECT text FROM postText WHERE id = :id");
     $stmt->execute(['id' => $id]);
     $text = $stmt->fetch(\PDO::FETCH_ASSOC);
     $stmt = $this->pdo->prepare("SELECT title, bgURL, authorID FROM posts WHERE postID = :id");
     $stmt->execute(['id' => $id]);
     $details = $stmt->fetch(\PDO::FETCH_ASSOC);
     $authorName = ['authorName' => Gatekeeper::findUserById($details['authorID'])->firstName . " " . Gatekeeper::findUserById($details['authorID'])->lastName];
     return array_merge($details, $text, $authorName);
 }
Exemple #4
0
 public function addUser(array $options, $output)
 {
     $user = Gatekeeper::findUserById($options['userid']);
     $ds = Gatekeeper::getDatasource();
     if (isset($options['permission'])) {
         // If it's a permission link it to the user
         $perm = new \Psecio\Gatekeeper\UserPermissionModel($ds, array('userId' => $user->id, 'permissionId' => $options['permission']));
         if ($ds->save($perm) === true) {
             $output->writeln('Permission linked to user successfully');
         }
     } elseif (isset($options['group'])) {
         // If it's a group link it to the user
         $group = new \Psecio\Gatekeeper\UserGroupModel($ds, array('userId' => $user->id, 'groupId' => $options['group']));
         if ($ds->save($group) === true) {
             $output->writeln('Group linked to user successfully');
         }
     }
 }
Exemple #5
0
            if (ACCEPT_JSON) {
                $app->response->setStatus(404);
            }
            $data = array('message' => $e->getMessage());
            echo $view->render('error/index.php', $data);
        }
    });
    $app->get('/delete/:userId', function ($userId) use($app, $view) {
        $data = array();
        try {
            $user = g::findUserById($userId);
            $ds = g::getDatasource();
            if ($ds->delete($user) === false) {
                throw new \Exception('Error deleting user.');
            }
            echo $view->render('users/delete.php', $data);
        } catch (\Exception $e) {
            if (ACCEPT_JSON) {
                $app->response->setStatus(404);
            }
            $data = array('message' => $e->getMessage());
            echo $view->render('error/index.php', $data);
        }
    });
    $app->get('/status/:userId', function ($userId) use($app, $view) {
        $user = g::findUserById($userId);
        $user->status === 'active' ? $user->deactivate() : $user->activate();
        $result = array('status' => $user->status, 'username' => $user->username);
        echo json_encode($result);
    });
});
Exemple #6
0
 /**
  * Only admins can access this method
  */
 public function logInAsAction()
 {
     if (!ctype_digit($_POST['id'])) {
         $this->flasher->error('User ID is invalid - not a number: ' . $_POST['id']);
         $this->redirect('/users');
     }
     $logInAs = Gatekeeper::findUserById($_POST['id']);
     if ($logInAs && !$logInAs->inGroup('admin')) {
         $_SESSION['superuser'] = $this->user->username;
         $_SESSION['user'] = $logInAs->username;
         $this->flasher->success('Successfully logged in as ' . $logInAs->username);
     } else {
         $this->flasher->error('Cannot log in as user with ID ' . $_POST['id']);
     }
     $this->redirect('/');
 }
 /**
  * Show the permissions for a user
  *
  * @param array $options Command line options
  * @param OutputInterface $output Output interface object
  */
 public function showUserGroups(array $options = array(), $output)
 {
     if (empty($options['id'])) {
         throw new \InvalidArgumentException('You must specify a user ID!');
     }
     $user = Gatekeeper::findUserById($options['id']);
     $output->writeln("\n" . 'Showing groups for <options=bold>' . $user->username . '</options=bold>');
     $params = array('userId' => $options['id']);
     $columns = array('name' => 'Name', 'description' => 'Description', 'created' => 'Date Created', 'updated' => 'Date Updated', 'id' => 'ID');
     $data = array();
     $ds = Gatekeeper::getDatasource();
     $groups = Gatekeeper::findUserGroups($params);
     foreach ($groups->toArray(true) as $group) {
         $groupModel = new \Psecio\Gatekeeper\GroupModel($ds);
         $groupModel = $ds->find($groupModel, array('id' => $group['groupId']));
         $data[] = $groupModel->toArray();
     }
     $this->buildTable($columns, $data, $output);
 }