Пример #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()))));
         }
     }
 }
Пример #2
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);
});