Exemplo n.º 1
0
$savedQueries->on('remove', function ($dataSource, $row) {
    $path = br()->config()->get('savedQueriesPath');
    try {
        br()->fs()->createDir($path)->checkWriteable($path);
        $rowid = $row['rowid'];
        $fileName = $path . 'saved.json';
        $queries = array();
        if (file_exists($fileName)) {
            if ($data = br()->fs()->loadFromFile($fileName)) {
                $queries = json_decode($data, true);
            }
        }
        $result = array();
        $deleted = array();
        foreach ($queries as $name => $row) {
            if (md5($name) != $rowid) {
                $result[$name] = $row;
            } else {
                $deleted = $row;
            }
        }
        $data = json_encode($result);
        br()->fs()->saveToFile($fileName, $data);
        return $deleted;
    } catch (Exception $e) {
        throw new Exception('To be able to remove queries folder "' . $path . '" must be writeable. Check About section, please.');
    }
});
br()->importLib('RESTBinder');
$rest = new BrRESTBinder();
$rest->route('/api/query', $queriesDataSource, array('filterMappings' => array(array('get' => 'hash', 'fields' => 'hash')), 'allowEmptyFilter' => true))->route('/api/libraryQueries', $libraryQueries, array('filterMappings' => array(array('get' => 'keyword', 'fields' => 'keyword')), 'allowEmptyFilter' => true))->route('/api/savedQueries', $savedQueries, array('filterMappings' => array(array('get' => 'keyword', 'fields' => 'keyword')), 'allowEmptyFilter' => true));
Exemplo n.º 2
0
<?php

br()->importLib('RESTBinder');
br()->importDataSource('users');
function dataSourcesLoader($className)
{
    if (preg_match('#DataSource$#', $className)) {
        $fileName = dirname(__DIR__) . '/datasources/' . $className . '.php';
        if (file_exists($fileName)) {
            require_once $fileName;
        }
    }
}
spl_autoload_register('dataSourcesLoader');
$rest = new BrRESTBinder();
$rest->route(new BrRESTUsersBinder(new BrDataSourceUsers()))->route('/api/some', 'SomeDataSource', array('security' => 'login', 'allowEmptyFilter' => true));
Exemplo n.º 3
0
 function doRouting()
 {
     $loginField = br()->auth()->getAttr('usersTable.loginField');
     br()->request()->route('/api/users/resetPassword/([-a-zA-Z0-9]+)', function ($matches) {
         $usersTable = br()->auth()->getAttr('usersTable.name');
         $passwordField = br()->auth()->getAttr('usersTable.passwordField');
         $passwordResetField = br()->auth()->getAttr('usersTable.passwordResetField');
         $emailField = br()->auth()->getAttr('usersTable.emailField');
         $plainPasswords = br()->auth()->getAttr('plainPasswords');
         if ($user = br()->db()->getRow('SELECT * FROM ' . $usersTable . ' WHERE ' . $passwordResetField . ' = ?&', $matches[1])) {
             if ($email = br($user, $emailField)) {
                 if ($mailTemplate = br()->auth()->getAttr('passwordReminder.passwordMail.template')) {
                     $password = substr(br()->guid(), 0, 8);
                     if ($plainPasswords) {
                         $finalPassword = $password;
                     } else {
                         $finalPassword = md5($password);
                     }
                     $data = array();
                     $data['password'] = $password;
                     $data['loginUrl'] = br()->request()->host() . br()->request()->baseUrl() . 'login.html?login='******'login'] . '&' . 'from=passwordRemind';
                     if ($message = br()->renderer()->fetch($mailTemplate, array('user' => $user, 'data' => $data))) {
                         if (br()->sendMail($email, br()->auth()->getAttr('passwordReminder.passwordMail.subject'), $message, array('sender' => br()->auth()->getAttr('passwordReminder.passwordMail.from')))) {
                             br()->db()->runQuery('UPDATE ' . $usersTable . ' SET ' . $passwordResetField . ' = null, ' . $passwordField . ' = ?& WHERE id = ?', $finalPassword, $user['id']);
                             br()->log()->writeLn('New password sent to ' . $email);
                             br()->log()->writeLn($user);
                             br()->response()->redirect($data['loginUrl']);
                             return true;
                         } else {
                             throw new Exception('Mail was not sent because of unknown error');
                         }
                     } else {
                         throw new Exception('We can not send you new password because mail template is empty');
                     }
                 } else {
                     throw new Exception('We can not send you new password because mail template is empty');
                 }
             } else {
                 throw new Exception('We can not send you new password because ther is not e-mail for your account');
             }
         } else {
             br()->response()->redirect(br()->request()->host() . br()->request()->baseUrl() . 'login.html?login='******'login'] . '&' . 'from=passwordRemindError');
             return true;
             // throw new Exception('Access denied');
         }
     });
     parent::route('/api/users/', $this->usersDataSource, array('security' => array('invoke' => '', '.*' => 'login'), 'filterMappings' => array(array('get' => 'keyword', 'type' => 'regexp', 'fields' => array($loginField)), array('get' => 'status', 'field' => 'status')), 'allowEmptyFilter' => true));
 }