Example #1
0
 public function setUp()
 {
     // TODO: need to figure out a way to remove this.
     Collection::from('auths');
     // only browser/server/device keys are affected by Role system.
     AppKey::current()->type = AppKey::TYPE_BROWSER;
     Context::setTrusted(false);
 }
Example #2
0
 public function call()
 {
     $app = $this->app;
     $app_key = Context::getKey();
     //
     // TODO: need a way to enable/disable logs for production use
     //
     // Log all queries
     $dispatcher = \Hook\Model\Collection::getEventDispatcher();
     $dispatcher->listen('illuminate.query', function ($query, $bindings, $time, $name) use(&$app) {
         $data = compact('bindings', 'time', 'name');
         // Format binding data for sql insertion
         foreach ($bindings as $i => $binding) {
             if ($binding instanceof \DateTime) {
                 $bindings[$i] = $binding->format('\'Y-m-d H:i:s\'');
             } else {
                 if (is_string($binding)) {
                     $bindings[$i] = "'{$binding}'";
                 }
             }
         }
         // Insert bindings into query
         $query = str_replace(array('%', '?'), array('%%', '%s'), $query);
         $query = vsprintf($query, $bindings);
         \Logger::debug($query);
     });
     if (!$app->request->isOptions() && $app_key) {
         // set application log writer for this app
         $log_file = storage_dir() . 'logs.txt';
         $app->log->setWriter(new LogWriter($log_file));
         // disable log if storage directory doesn't exists.
         // maybe we're on a readonly filesystem
         $app->log->setEnabled(is_writable($log_file));
         if (strpos($app->request->getPath(), "/apps/") === false) {
             $app->log->info($app->request->getIp() . ' - [' . date('d-m-Y H:i:s') . '] ' . $app->request->getMethod() . ' ' . $app->request->getResourceUri());
             $app->log->info('Params: ' . json_encode($app->request->params()));
         }
     }
     return $this->next->call();
 }
Example #3
0
 protected function fireEvent($event, $payload)
 {
     $dispatcher = Collection::getEventDispatcher();
     if (!$dispatcher) {
         return true;
     }
     $event = "eloquent.{$event}: " . $this->name;
     return $dispatcher->until($event, $payload);
 }
Example #4
0
 public function beforeSave()
 {
     // Only a trusted context can change the 'role' attribute
     if ($this->isDirty('role') && (!Context::isTrusted() && !Role::isTrusted())) {
         $this->role = isset($this->original['role']) ? $this->original['role'] : null;
     }
     if (!$this->isTrustedAction() && !$this->isUpdateAllowed()) {
         throw new ForbiddenException("not_allowed");
     }
     // Update password
     if ($this->isDirty('password')) {
         $this->password_salt = sha1(uniqid(rand(), true));
         $this->password = static::password_hash($this->password, $this->password_salt);
     }
     parent::beforeSave();
 }