コード例 #1
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');
});
コード例 #2
0
        $collection = ['name' => $name, 'slug' => $slug, 'fields' => isset($_POST['fields']) ? $_POST['fields'] : null];
        if (!$collection['fields']) {
            alerts('error', 'Collection must have fields.');
        } else {
            $names = [];
            foreach ($collection['fields'] as $n => $field) {
                $field['name'] = trim($field['name']);
                if ($field['name'] === '') {
                    alerts('error', 'Enter field name (' . ($n + 1) . ')');
                } elseif (in_array($field['name'], $names)) {
                    alerts('error', 'Field with same name aready exist (' . ($n + 1) . ')');
                } else {
                    $names[] = $field['name'];
                }
                if ($field['type'] === 'select' && trim($field['options']) === '') {
                    alerts('error', 'Field with type `select` must have options (' . ($n + 1) . ')');
                }
                $collection['fields'][$n] = ['name' => trim($field['name']), 'type' => $field['type'], 'label' => $field['label'], 'default' => $field['default_value'], 'required' => isset($field['required']) ? true : false, 'options' => $field['options']];
            }
        }
        if (count(alerts('error')) === 0) {
            if (jdb_update('collections', $collection, $uid)) {
                flash('info', 'Collection updated successfuly.');
                redirect(site() . 'collections/collection/' . $uid);
            } else {
                alerts('error', 'Something was wron, collection do not created.');
            }
        }
    }
    echo phtml('collection', ['collection' => $collection]);
});