Example #1
0
 public function index()
 {
     Breadcrumbs::add('', 'Credentials');
     $data['breadcrumbs'] = Breadcrumbs::get();
     // User is admin, show index of users
     $data['title'] = 'Credentials';
     $data['current_user'] = $current_user;
     $data['footer-logic'] = 'credentials/index-footer';
     View::renderTemplate('header', $data);
     View::render('credentials/index', $data);
     View::renderTemplate('footer', $data);
 }
Example #2
0
 public function index()
 {
     $current_user = User::current();
     if (!$current_user->isAdmin()) {
         http_response_code(403);
         echo "Access denied";
         return;
     }
     $since = $_GET['start'];
     $until = $_GET['end'];
     if ($since == NULL) {
         $since = strtotime("midnight");
     } else {
         $since = $this->validate_date($since);
         if (!$since) {
             http_response_code(409);
             echo 'Invalid start date';
             return;
         }
         $since = strtotime("midnight", $since);
     }
     if ($until == NULL) {
         $until = strtotime("tomorrow");
     } else {
         $until = $this->validate_date($until);
         if (!$until) {
             http_response_code(409);
             echo 'Invalid end date';
             return;
         }
         $until = strtotime("midnight", $until);
     }
     Breadcrumbs::add(DIR, 'Credentials');
     Breadcrumbs::add('', 'Audit');
     $data['breadcrumbs'] = Breadcrumbs::get();
     $data['title'] = 'Audit';
     $data['current_user'] = $current_user;
     $data['footer-logic'] = 'credentials/audit-footer';
     $data['logs'] = $this->audit->get($since, $until);
     $data['since'] = $since;
     $data['until'] = $until;
     $data['span'] = $until - $since;
     View::renderTemplate('header', $data);
     View::render('credentials/audit', $data);
     View::renderTemplate('footer', $data);
 }
Example #3
0
 public function index($id = NULL)
 {
     $current_user = User::current();
     if ($id == NULL) {
         if ($current_user->isAdmin()) {
             // User is admin, show index of users
             Breadcrumbs::add(DIR, 'Credentials');
             Breadcrumbs::add('', 'Users');
             $data['breadcrumbs'] = Breadcrumbs::get();
             $data['title'] = 'User overview';
             $data['current_user'] = $current_user;
             $data['users'] = $this->users->getAll();
             $data['footer-logic'] = 'credentials/users-footer';
             View::renderTemplate('header', $data);
             View::render('credentials/users', $data);
             View::renderTemplate('footer', $data);
         } else {
             // User is not admin, redirect to their page
             $this->index($current_user->id);
         }
     } else {
         $user = $this->users->getById($id);
         if ($user == NULL) {
             http_response_code(404);
             echo "Not found";
             return;
         }
         if ($current_user->id != $user->id && !$current_user->isAdmin()) {
             http_response_code(403);
             echo "Not allowed";
             return;
         }
         Breadcrumbs::add(DIR, 'Credentials');
         Breadcrumbs::add(DIR . 'users', 'Users');
         Breadcrumbs::add('', $user->login);
         $data['breadcrumbs'] = Breadcrumbs::get();
         $data['title'] = 'User ' . $user->login;
         $data['current_user'] = $current_user;
         $data['user'] = $user;
         $data['keys'] = $this->keys->getAllByUser($user);
         $data['footer-logic'] = 'credentials/user-footer';
         View::renderTemplate('header', $data);
         View::render('credentials/user', $data);
         View::renderTemplate('footer', $data);
     }
 }