public function findBySponsorId($sponsorId) { $sql = 'select u.* from users u, sponsor_user su' . ' where su.sponsor_id = :sponsorId and u.id = su.user_id'; $results = $this->fetch($sql, ['sponsorId' => $sponsorId]); foreach ($results as $result) { $user = new \Conftrack\Model\User($this->getDb()); $user->load($result, false); $this->add($user); } }
public function __invoke($request, $response, $next) { $db = $this->container->get('db'); $session = $this->getSession(); $currentUser = $session->getSegment('default')->get('user'); $user = new \Conftrack\Model\User($db); $user->findById($currentUser['id']); // Load up Invoke and make the checks $enforcer = new Enforcer(__DIR__ . '/../../config/routes.yml'); $allowed = $enforcer->isAuthorized(new \Conftrack\InvokeUser($user), new \Psecio\Invoke\Resource()); if ($allowed === false) { // redirect! not allowed return $response->withRedirect('/error'); } // Allowed, pass on through $response = $next($request, $response); return $response; }
$message = 'User created successfully!'; $data['success'] = true; } catch (\Exception $e) { $message = "Error: " . implode("\n", $user->getMessages()); } $type = $data['success'] == false ? 'danger' : 'success'; $this->flash->addMessage($type, $message); $this->view->render($response, 'user/register.twig', $data); }); $app->get('/dashboard', function ($request, $response, $args) { $data = []; $this->view->render($response, 'user/dashboard.twig', $data); }); $app->get('/view/{userId}', function ($request, $response, $args) { $db = $this->getContainer()->get('db'); $user = new \Conftrack\Model\User($db); $user->findById($args['userId']); $groups = new \Conftrack\Collection\Groups($db); $groups->findAll(); $data = ['viewUser' => $user->toArray(), 'sponsors' => $user->sponsors->toArray(true), 'groups' => $groups->toArray(true), 'userGroups' => $user->groups->toArray(true)]; $this->view->render($response, 'user/view.twig', $data); }); $app->post('/{userId}/group', function ($request, $response, $args) { $data = ['success' => false]; $body = $request->getParsedBody(); $userGroup = new \Conftrack\Model\UserGroup($this->getContainer()->get('db')); $userGroup->load(['user_id' => $args['userId'], 'group_id' => $body['groupId']]); try { $userGroup->verify(); $userGroup->save(); $data['success'] = true;
<?php $app->group('/admin', function () use($app) { /* Default page route */ $app->get('/users', function ($request, $response, $args) { $users = new \Conftrack\Collection\Users($this->getContainer()->get('db')); $users->findAll(); $data = ['users' => $users->toArray(true)]; $this->view->render($response, 'admin/users.twig', $data); }); $app->post('/users/status', function ($request, $response, $args) { $data = ['success' => false]; $body = $request->getParsedBody(); $user = new \Conftrack\Model\User($this->getContainer()->get('db')); $user->findById($body['userId']); if ($user->id == null) { throw new \Exception('User not found!'); } else { $user->status == 'active' ? $user->disable() : $user->enable(); $data['success'] = true; } return $response->withJson($data); }); $app->get('/groups', function ($request, $response, $args) { $groups = new \Conftrack\Collection\Groups($this->getContainer()->get('db')); $groups->findAll(); $data = ['groups' => $groups->toArray(true)]; $this->view->render($response, 'groups/index.twig', $data); }); $app->get('/groups/create', function ($request, $response, $args) { $data = [];