Exemplo n.º 1
0
            $newresult = substr($newresult, strpos($newresult, " ") + 1);
            $messageBody = str_replace($result, $newresult, $messageBody);
            if ($i == $len - 1) {
                if ($i > 0) {
                    $recipientString .= " and " . $newresult;
                } else {
                    $recipientString .= $newresult;
                }
            } else {
                $recipientString .= $newresult . ", ";
            }
            $i++;
        }
        $mail = new Directus\Mail\Mailer();
        foreach ($userRecipients as $recipient) {
            $usersTableGateway = new DirectusUsersTableGateway($acl, $ZendDb);
            $user = $usersTableGateway->findOneBy('id', $recipient);
            if (isset($user) && $user['email_messages'] == 1) {
                $NotificationMail = new Directus\Mail\NotificationMail($user['email'], $requestPayload['subject'], $requestPayload['message']);
                $mail->send($NotificationMail);
            }
        }
    }
    $newRecord = $TableGateway->manageRecordUpdate("directus_messages", $requestPayload, TableGateway::ACTIVITY_ENTRY_MODE_DISABLED);
    $params['id'] = $newRecord['id'];
    // GET all table entries
    $entries = $TableGateway->getEntries($params);
    JsonView::render($entries);
});
/**
 * EXCEPTION LOG
Exemplo n.º 2
0
function getUsers()
{
    global $ZendDb, $acl;
    $tableGateway = new TableGateway($acl, 'directus_users', $ZendDb);
    $users = $tableGateway->getEntries(['table_name' => 'directus_users', 'perPage' => 1000, STATUS_COLUMN_NAME => STATUS_ACTIVE_NUM, 'columns_visible' => [STATUS_COLUMN_NAME, 'avatar', 'first_name', 'last_name', 'group', 'email', 'position', 'last_access']]);
    // Lets get the gravatar if no avatar is set.
    // TODO: Add this on insert/update of any user.
    $usersRowsToUpdate = [];
    foreach ($users['rows'] as $user) {
        $hasAvatar = array_key_exists('avatar', $user) ? $user['avatar'] : false;
        $hasEmail = array_key_exists('email', $user) ? $user['email'] : false;
        if (!$hasAvatar && $hasEmail) {
            $avatar = DirectusUsersTableGateway::get_avatar($user['email']);
            if ($avatar) {
                $user['avatar'] = $avatar;
                array_push($usersRowsToUpdate, $user);
            }
        }
    }
    if ($usersRowsToUpdate) {
        $tableGateway->updateCollection($usersRowsToUpdate);
    }
    return $users;
}
Exemplo n.º 3
0
 /**
  * Construct Acl provider
  * @return \Directus\Acl
  */
 private static function acl()
 {
     $acl = new acl();
     $db = self::get('ZendDb');
     $DirectusTablesTableGateway = new DirectusTablesTableGateway($acl, $db);
     $getTables = function () use($DirectusTablesTableGateway) {
         return $DirectusTablesTableGateway->select()->toArray();
     };
     $tableRecords = $DirectusTablesTableGateway->memcache->getOrCache(MemcacheProvider::getKeyDirectusTables(), $getTables, 1800);
     $magicOwnerColumnsByTable = [];
     foreach ($tableRecords as $tableRecord) {
         if (!empty($tableRecord['user_create_column'])) {
             $magicOwnerColumnsByTable[$tableRecord['table_name']] = $tableRecord['user_create_column'];
         }
     }
     $acl::$cms_owner_columns_by_table = $magicOwnerColumnsByTable;
     if (AuthProvider::loggedIn()) {
         $currentUser = AuthProvider::getUserInfo();
         $Users = new DirectusUsersTableGateway($acl, $db);
         $cacheFn = function () use($currentUser, $Users) {
             return $Users->find($currentUser['id']);
         };
         $cacheKey = MemcacheProvider::getKeyDirectusUserFind($currentUser['id']);
         $currentUser = $Users->memcache->getOrCache($cacheKey, $cacheFn, 10800);
         if ($currentUser) {
             $privilegesTable = new DirectusPrivilegesTableGateway($acl, $db);
             $acl->setGroupPrivileges($privilegesTable->getGroupPrivileges($currentUser['group']));
         }
     }
     return $acl;
 }
Exemplo n.º 4
0
 */
$app->config('debug', false);
$exceptionView = new ExceptionView();
$exceptionHandler = function (\Exception $exception) use($app, $exceptionView) {
    $exceptionView->exceptionHandler($app, $exception);
};
$app->error($exceptionHandler);
/**
 * Bootstrap Providers
 */
$ZendDb = Bootstrap::get('ZendDb');
$acl = Bootstrap::get('acl');
/**
 * Authentication
 */
$DirectusUsersTableGateway = new DirectusUsersTableGateway($acl, $ZendDb);
Auth::setUserCacheRefreshProvider(function ($userId) use($DirectusUsersTableGateway) {
    $cacheFn = function () use($userId, $DirectusUsersTableGateway) {
        return $DirectusUsersTableGateway->find($userId);
    };
    $cacheKey = MemcacheProvider::getKeyDirectusUserFind($userId);
    $user = $DirectusUsersTableGateway->memcache->getOrCache($cacheKey, $cacheFn, 10800);
    return $user;
});
if (Auth::loggedIn()) {
    $user = Auth::getUserRecord();
    $acl->setUserId($user['id']);
    $acl->setGroupId($user['group']);
}
$app->hook('slim.before.dispatch', function () use($app) {
    if (!Auth::loggedIn()) {