コード例 #1
0
ファイル: functions.php プロジェクト: s-melnikov/simple-cms
function alerts($type, $text = null)
{
    $alerts = stash('alerts');
    if (!$alerts) {
        $alerts = ['info' => [], 'error' => [], 'warn' => []];
    }
    if (func_num_args() === 1) {
        return $alerts[$type];
    }
    $alerts[$type][] = $text;
    stash('alerts', $alerts);
}
コード例 #2
0
ファイル: index.php プロジェクト: s-melnikov/simple-cms
$app_base_url = strlen($app_base) ? "/{$app_base}" : $app_base;
config('url', $app_base_url);
config('templates', 'views');
require APP_DIR . 'functions.php';
if (!session('user_uid')) {
    if (isset($_POST['email']) && isset($_POST['password'])) {
        $users = jdb_select('.users', ['email' => trim($_POST['email'])]);
        if (count($users)) {
            $user = $users[0];
            if ($user['hash'] === hash('sha256', trim($_POST['password']))) {
                session('user_uid', $user['_uid']);
                redirect($_SERVER['REQUEST_URI']);
            } else {
                alerts('error', 'Wrong email or password!');
            }
        } else {
            alerts('error', 'Wrong email or password!');
        }
    }
    echo phtml('login', [], false);
    exit;
}
stash('user', jdb_select('.users', session('user_uid'))[0]);
if (flash('info')) {
    alerts('info', flash('info'));
}
require 'routes/routes.main.php';
require 'routes/routes.users.php';
require 'routes/routes.settings.php';
require 'routes/routes.collections.php';
dispatch();
コード例 #3
0
ファイル: dispatch.php プロジェクト: matthew0x40/apply
function content($value = null)
{
    return stash('$content$', $value);
}
コード例 #4
0
    if (!preg_match('/^\\S+@\\S+$/', $email)) {
        alerts('error', 'Email must have format: abc@xyz.com.');
    }
    if (stash('user')['email'] !== $email) {
        $users = jdb_select('.users', ['email' => $email]);
        if (count($users) > 0) {
            alerts('error', 'User with same email alredy exists.');
        }
    }
    if ($new_password !== '') {
        if (stash('user')['hash'] !== hash('sha256', $password)) {
            alerts('error', 'Wrong password.');
        }
        if (!preg_match('/.{6}/', $new_password)) {
            alerts('error', 'New password must containt minimum 6 characters.');
        }
    }
    if (count(alerts('error')) === 0) {
        $update = ['login' => $login, 'email' => $email];
        if ($new_password) {
            $update['hash'] = hash('sha256', $new_password);
        }
        if (jdb_update('.users', $update, stash('user')['_uid'])) {
            alerts('info', 'User updated.');
            stash('user', jdb_select('.users', stash('user')['_uid'])[0]);
        } else {
            alerts('error', 'Something was wrong, user not updated.');
        }
    }
    echo phtml('user');
});
コード例 #5
0
ファイル: functions.php プロジェクト: matthew0x40/apply
function is_stashed($key)
{
    return stash($key) !== null;
}
コード例 #6
0
assert(['name' => '', 'email' => ''] === blanks('name', 'email'));
# ip() - least priority first
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
assert(ip() === $_SERVER['REMOTE_ADDR']);
$_SERVER['HTTP_X_FORWARDED_FOR'] = '127.0.0.2';
assert(ip() === $_SERVER['HTTP_X_FORWARDED_FOR']);
$_SERVER['HTTP_CLIENT_IP'] = '127.0.0.3';
assert(ip() === $_SERVER['HTTP_CLIENT_IP']);
# stash tests
stash('name', 'dispatch');
assert(stash('name') === 'dispatch');
stash('name', null);
assert(stash('name') === null);
stash('name', 'dispatch');
stash();
assert(stash('name') === null);
# invalid call
try {
    headers();
} catch (Exception $e) {
    assert($e instanceof BadFunctionCallException);
}
# fake request headers
$_SERVER['CONTENT_LENGTH'] = 1024;
$_SERVER['CONTENT_TYPE'] = 'application/x-www-form-urlencoded';
$_SERVER['HTTP_X_AUTH_TOKEN'] = 'some-token';
assert(headers('content-length') === 1024);
assert(headers('content-type') === 'application/x-www-form-urlencoded');
assert(headers('x-auth-token') === 'some-token');
if (function_exists('xdebug_get_headers')) {
    # test header setting