示例#1
0
文件: Form.php 项目: moiseh/metapages
 public static function addError($message, $field = null)
 {
     $form_errors = isset($GLOBALS['form_errors']) ? (array) $GLOBALS['form_errors'] : array();
     if (!in_array($message, $form_errors)) {
         \Meta\Core\Flash::error($message);
         $GLOBALS['form_errors'][] = $message;
     }
 }
示例#2
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()))));
         }
     }
 }
示例#3
0
    }
    // convert new password to md5 on "users" table
    // this can filled on user edit form
    if (is_post() && isset($_REQUEST['id']) && isset($_REQUEST['password_new']) && strlen($_REQUEST['password_new']) > 0) {
        \Meta\Core\Db::execute('UPDATE users SET password = md5(?) WHERE id = ?', array($_REQUEST['password_new'], $_REQUEST['id']));
    }
    return $page;
});
Page::beforeRender('frame-user-groups', function ($page) {
    // modify $page array here
    // prevent unauthorized actions
    if (is_demo() && isset($_REQUEST['action']) && isset($_REQUEST['id'])) {
        if (is_post() || $_REQUEST['action'] == 'delete') {
            $user_id = \Meta\Core\Db::query('SELECT user_id FROM user_groups WHERE id = ?', array($_REQUEST['id']))->fetchColumn();
            if ($user_id == 1) {
                \Meta\Core\Flash::error(t('Sorry, but you cannot modify the Admin user in demo mode'));
                header("Location: " . urldecode($_GET['url_from']));
                exit;
            }
        }
    }
    return $page;
});
Page::beforeRender('manage-files', function ($page) {
    // scan all files. if the number is different than the table, then re populate all entirely table
    $files = \Meta\Core\FileSystem::listAll();
    $dbCountFiles = \Meta\Core\Db::query('SELECT COUNT(*) FROM files')->fetchColumn();
    if (count($files) > 0 && count($files) != $dbCountFiles) {
        // delete all and insert files list
        \Meta\Core\Db::execute('DELETE FROM files');
        foreach ($files as $file) {
示例#4
0
 // form
 \Meta\Core\Form::validateRequired('name');
 \Meta\Core\Form::validateRequired('label');
 $new_name = \Meta\Core\Form::value('name');
 // page rename action detect
 $renamed = false;
 if (is_post() && $new_name != $path) {
     $renamed = true;
     // validate page exists
     if (isset($pages[$new_name])) {
         \Meta\Core\Form::addError(t('This page already exists'));
     }
 }
 if (\Meta\Core\Form::hasValidated()) {
     if (is_demo()) {
         \Meta\Core\Flash::error(\Meta\Builder::demoMsg());
     } else {
         \Meta\Core\Flash::success(t('Page updated.'));
         // changes the new page name
         if ($renamed) {
             $pages[$new_name] = $pages[$path];
             unset($pages[$path]);
             $path = $new_name;
         }
         // atualiza array
         $page = new \Meta\Builder\Page($path, $pageArray);
         $page->label = \Meta\Core\Form::value('label');
         $page->showonmenu = \Meta\Core\Form::checked('showonmenu');
         $page->checkperms = \Meta\Core\Form::checked('checkperms');
         $page->groupsAllowed = array_keys((array) $_REQUEST['groups']);
         $page->parentmenu = \Meta\Core\Form::value('parentmenu');
示例#5
0
 protected function messageError($message)
 {
     Flash::error($message);
     return true;
 }
示例#6
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);
});
示例#7
0
文件: Form.php 项目: moiseh/metapages
 public function validateForm()
 {
     $validated = true;
     foreach ((array) $this->fields as $field) {
         $field instanceof Field;
         $field->executeValidations();
         if ($field->getErrors()) {
             $validated = false;
         }
     }
     if (!$validated) {
         Flash::error(t('One or more problem(s) occurred with the form...'));
     }
     return $validated;
 }