Example #1
0
 public static function checkAuth()
 {
     if (preg_match('/(builder\\/(.*)|^builder$)/', current_path())) {
         if (User::hasLoggedUser() && !User::logged()->isAdmin) {
             \Meta\Core\Flash::error(t('You need to login with user that have the "Admin user" flag to access the builder interface.'));
             User::logout();
         }
         if (!User::hasLoggedUser()) {
             redirect(url('user-login', array('back_to' => urlencode(current_path()))));
         }
     }
 }
Example #2
0
 public function buildItems($pages = array())
 {
     $items = array();
     // gera uma lista mais "simples" de itens para depois gerar o menu
     foreach ($pages as $path => $page) {
         // checks the user permissions
         if (isset($page['checkperms'])) {
             $hasPerms = !$page['checkperms'] || $page['checkperms'] && User::hasLoggedUser() && User::logged()->isInGroups((array) $page['groupsAllowed']);
         } else {
             $hasPerms = true;
         }
         if ($hasPerms) {
             // adiciona o path
             $items[$path] = array('path' => $path, 'label' => $page['label'], 'parentmenu' => isset($page['parentmenu']) ? $page['parentmenu'] : NULL, 'icon' => isset($page['menuIcon']) ? $page['menuIcon'] : NULL, 'pageType' => isset($page['pageType']) ? $page['pageType'] : NULL, 'showonmenu' => isset($page['showonmenu']) ? $page['showonmenu'] : NULL, 'hasPermission' => $hasPerms);
         }
     }
     asort($items);
     return $items;
 }
Example #3
0
 /**
  * @return boolean
  */
 public function isUserAllowed()
 {
     if ($this->checkperms) {
         if (!User::hasLoggedUser()) {
             return false;
         }
         return User::logged()->isInGroups($this->groupsAllowed);
     }
     return true;
 }
Example #4
0
 public function userIsAdmin()
 {
     return User::hasLoggedUser() && User::logged()->isAdmin;
 }
Example #5
0
<?php

use Meta\Core\Flash;
use Meta\Core\Form;
use Meta\Core\User;
use Meta\Builder\Page;
route_add('user-login', function () {
    set_page_title('User authentication');
    Form::validateRequired('username');
    Form::validateRequired('password');
    if (Form::hasValidated()) {
        if (User::authenticate($_POST['username'], $_POST['password'])) {
            if (isset($_GET['back_to'])) {
                redirect(urldecode($_GET['back_to']));
            } else {
                redirect(PAGE_HOME);
            }
        } else {
            Flash::error(t('Invalid username or password!'));
        }
    }
    echo Page::renderLayout(array('content' => render('user-login.php')));
});
route_add('user-logout', function () {
    User::logout();
    redirect(PAGE_HOME);
});