Example #1
0
 public static function send($viewPath, $data, $callback)
 {
     $config = Bootstrap::get('config');
     $mailer = Bootstrap::get('mailer');
     if (!$mailer) {
         throw new InvalidArgumentException(__t('mail_configuration_no_defined'));
     }
     $DirectusSettingsTableGateway = new \Zend\Db\TableGateway\TableGateway('directus_settings', Bootstrap::get('zendDb'));
     $rowSet = $DirectusSettingsTableGateway->select();
     $settings = [];
     foreach ($rowSet as $setting) {
         $settings[$setting['collection']][$setting['name']] = $setting['value'];
     }
     $instance = new static($mailer, $settings);
     $message = Swift_Message::newInstance();
     // default mail from address
     $mailConfig = $config['mail'];
     $message->setFrom($mailConfig['from']);
     $bcc = ArrayUtils::get($mailConfig, 'bcc', null);
     if ($bcc !== null) {
         $message->setBcc($bcc);
     }
     $cc = ArrayUtils::get($mailConfig, 'cc', null);
     if ($cc !== null) {
         $message->setCc($cc);
     }
     call_user_func($callback, $message);
     if ($message->getBody() == null) {
         // Slim Extras View twig act weird on this version
         $viewContent = $instance->getViewContent($viewPath, $data);
         $message->setBody($viewContent, 'text/html');
     }
     $instance->sendMessage($message);
 }
Example #2
0
 public function call()
 {
     $corsOptions = ArrayUtils::get($this->app->container->get('config'), 'cors', []);
     if (ArrayUtils::get($corsOptions, 'enabled', false)) {
         $response = $this->app->response();
         $response->header('Access-Control-Allow-Origin', ArrayUtils::get($corsOptions, 'origin', '*'));
         foreach (ArrayUtils::get($corsOptions, 'headers', []) as list($headerType, $headerValue)) {
             $response->header($headerType, $headerValue);
         }
     }
     if (!$this->app->request()->isOptions()) {
         $this->next->call();
     }
 }
Example #3
0
 protected function formatColumnFromInfo($columnInfo, $directusColumnInfo)
 {
     $matches = [];
     preg_match('#^([a-zA-Z]+)(\\(.*\\)){0,1}$#', $columnInfo->getDataType(), $matches);
     $dataType = strtoupper($matches[1]);
     return ['id' => $columnInfo->getName(), 'column_name' => $columnInfo->getName(), 'type' => $dataType, 'char_length' => $columnInfo->getCharacterMaximumLength(), 'is_nullable' => $columnInfo->getIsNullable() ? 'YES' : 'NO', 'default_value' => $columnInfo->getColumnDefault() == 'NULL' ? NULL : $columnInfo->getColumnDefault(), 'comment' => '', 'sort' => $columnInfo->getOrdinalPosition(), 'column_type' => $columnInfo->getDataType(), 'ui' => ArrayUtils::get($directusColumnInfo, 'ui', null), 'hidden_list' => ArrayUtils::get($directusColumnInfo, 'hidden_list', 0), 'hidden_input' => ArrayUtils::get($directusColumnInfo, 'hidden_input', 0), 'relationship_type' => ArrayUtils::get($directusColumnInfo, 'relationship_type', null), 'related_table' => ArrayUtils::get($directusColumnInfo, 'related_table', null), 'junction_table' => ArrayUtils::get($directusColumnInfo, 'junction_table', null), 'junction_key_left' => ArrayUtils::get($directusColumnInfo, 'junction_key_left', null), 'junction_key_right' => ArrayUtils::get($directusColumnInfo, 'junction_key_right', null), 'required' => ArrayUtils::get($directusColumnInfo, 'required', 0)];
 }
Example #4
0
 public function testGetItem()
 {
     $item = ['name' => 'Jim'];
     $this->assertEquals(ArrayUtils::get($item, 'name'), 'Jim');
     $this->assertEquals(ArrayUtils::get($item, 'age', 18), 18);
 }
Example #5
0
 /**
  * Add Directus default user
  *
  * @param array $data
  * @return array
  */
 public static function addDefaultUser($data)
 {
     $db = Bootstrap::get('ZendDb');
     $tableGateway = new TableGateway('directus_users', $db);
     $hash = password_hash($data['directus_password'], PASSWORD_DEFAULT, ['cost' => 12]);
     $data['user_salt'] = StringUtils::randomString();
     $data['user_token'] = StringUtils::randomString(32);
     $data['avatar'] = get_gravatar($data['directus_email']);
     $tableGateway->insert(['active' => 1, 'first_name' => 'Admin', 'last_name' => 'User', 'email' => $data['directus_email'], 'password' => $hash, 'salt' => $data['user_salt'], 'avatar' => $data['avatar'], 'group' => 1, 'token' => $data['user_token'], 'language' => ArrayUtils::get($data, 'default_language', 'en')]);
     return $data;
 }
Example #6
0
 private static function formatColumnRow($row)
 {
     $columnName = $row['column_name'];
     foreach ($row as $key => $value) {
         if (is_null($value)) {
             unset($row[$key]);
         }
     }
     unset($row['table_name']);
     $row['id'] = $columnName;
     $row['options'] = array();
     // Many-to-Many type it actually can be null,
     // it's based on a junction table, not a real column.
     // Issue #612 https://github.com/RNGR/directus6/issues/612
     if (array_key_exists('type', $row) && $row['type'] == 'MANYTOMANY') {
         $row['is_nullable'] = "YES";
     }
     if ($row['is_nullable'] == "NO") {
         $row["required"] = true;
     }
     // Basic type casting. Should eventually be done with the schema
     $row["required"] = (bool) $row['required'];
     $row["system"] = (bool) $row["system"];
     $row["master"] = (bool) $row["master"];
     $row["hidden_list"] = (bool) $row["hidden_list"];
     $row["hidden_input"] = (bool) $row["hidden_input"];
     //$row["is_writable"] = !in_array($row['id'], $writeFieldBlacklist);
     if (array_key_exists('sort', $row)) {
         $row["sort"] = (int) $row['sort'];
     }
     $hasMaster = $row["master"];
     // Default UI types.
     if (!isset($row["ui"])) {
         $row['ui'] = self::columnTypeToUIType($row['type']);
     }
     // Defualts as system columns
     if ($row["id"] == 'id' || $row["id"] == STATUS_COLUMN_NAME || $row["id"] == 'sort') {
         $row["system"] = true;
         $row["hidden"] = true;
     }
     if (array_key_exists('table_related', $row)) {
         $row['relationship'] = array();
         $row['relationship']['type'] = ArrayUtils::get($row, 'relationship_type');
         $row['relationship']['table_related'] = $row['table_related'];
         unset($row['relationship_type']);
         unset($row['table_related']);
         if (array_key_exists('junction_key_left', $row)) {
             $row['relationship']['junction_key_left'] = $row['junction_key_left'];
             unset($row['junction_key_left']);
         }
         if (array_key_exists('junction_key_right', $row)) {
             $row['relationship']['junction_key_right'] = $row['junction_key_right'];
             unset($row['junction_key_right']);
         }
         if (array_key_exists('junction_table', $row)) {
             $row['relationship']['junction_table'] = $row['junction_table'];
             unset($row['junction_table']);
         }
     }
     return $row;
 }
Example #7
0
 private static function formatColumnRow($row)
 {
     $columnName = $row['column_name'];
     foreach ($row as $key => $value) {
         if (is_null($value)) {
             unset($row[$key]);
         }
     }
     unset($row['table_name']);
     $row['id'] = $columnName;
     $row['options'] = [];
     // Many-to-Many type it actually can be null,
     // it's based on a junction table, not a real column.
     // Issue #612 https://github.com/RNGR/directus6/issues/612
     if (array_key_exists('type', $row) && $row['type'] == 'ALIAS') {
         $row['is_nullable'] = 'YES';
     }
     $hasDefaultValue = isset($row['default_value']);
     $anAlias = static::isColumnTypeAnAlias($row['type']);
     if ($row['is_nullable'] === 'NO' && !$hasDefaultValue && !$anAlias) {
         $row['required'] = true;
     }
     // Basic type casting. Should eventually be done with the schema
     if ($hasDefaultValue) {
         $row['default_value'] = SchemaManager::parseType($row['default_value'], $row['type']);
     }
     $row['required'] = (bool) $row['required'];
     $row['system'] = (bool) static::isSystemColumn($row['id']);
     $row['hidden_list'] = (bool) $row['hidden_list'];
     $row['hidden_input'] = (bool) $row['hidden_input'];
     //$row['is_writable'] = !in_array($row['id'], $writeFieldBlacklist);
     if (array_key_exists('sort', $row)) {
         $row['sort'] = (int) $row['sort'];
     }
     // Default UI types.
     if (!isset($row['ui'])) {
         $row['ui'] = self::columnTypeToUIType($row['type']);
     }
     // Defualts as system columns
     if (static::isSystemColumn($row['id'])) {
         $row['system'] = true;
         $row['hidden'] = true;
     }
     if (array_key_exists('related_table', $row)) {
         $row['relationship'] = [];
         $row['relationship']['type'] = ArrayUtils::get($row, 'relationship_type');
         $row['relationship']['related_table'] = $row['related_table'];
         unset($row['relationship_type']);
         unset($row['related_table']);
         if (array_key_exists('junction_key_left', $row)) {
             $row['relationship']['junction_key_left'] = $row['junction_key_left'];
             unset($row['junction_key_left']);
         }
         if (array_key_exists('junction_key_right', $row)) {
             $row['relationship']['junction_key_right'] = $row['junction_key_right'];
             unset($row['junction_key_right']);
         }
         if (array_key_exists('junction_table', $row)) {
             $row['relationship']['junction_table'] = $row['junction_table'];
             unset($row['junction_table']);
         }
     }
     return $row;
 }
Example #8
0
    }
    return JsonView::render($responseData);
}
/**
 * Slim Routes
 * (Collections arranged alphabetically)
 */
$app->post("/{$v}/auth/request-token/?", function () use($app, $ZendDb) {
    $response = ['success' => false, 'message' => __t('incorrect_email_or_password')];
    $request = $app->request();
    // @NOTE: Slim request do not parse a json request body
    //        We need to parse it ourselves
    if ($request->getMediaType() == 'application/json') {
        $jsonRequest = json_decode($request->getBody(), true);
        $email = ArrayUtils::get($jsonRequest, 'email', false);
        $password = ArrayUtils::get($jsonRequest, 'password', false);
    } else {
        $email = $request->post('email');
        $password = $request->post('password');
    }
    if ($email && $password) {
        $user = Auth::getUserByAuthentication($email, $password);
        if ($user) {
            unset($response['message']);
            $response['success'] = true;
            $response['data'] = ['token' => $user['token']];
        }
    }
    return JsonView::render($response);
})->name('request_token');
$app->post("/{$v}/auth/login/?", function () use($app, $ZendDb, $acl, $requestNonceProvider) {
Example #9
0
 public function addColumn($tableName, $tableData)
 {
     // @TODO: enforce permission
     $directus_types = ['MANYTOMANY', 'ONETOMANY', 'ALIAS'];
     $relationshipType = ArrayUtils::get($tableData, 'relationship_type', null);
     // TODO: list all types which need manytoone ui
     // Hard-coded
     $manytoones = ['single_file', 'many_to_one', 'many_to_one_typeahead', 'MANYTOONE'];
     if (in_array($relationshipType, $directus_types)) {
         //This is a 'virtual column'. Write to directus schema instead of MYSQL
         $this->addVirtualColumn($tableName, $tableData);
     } else {
         $this->addTableColumn($tableName, $tableData);
         // Temporary solutions to #481, #645
         if (array_key_exists('ui', $tableData) && in_array($tableData['ui'], $manytoones)) {
             $tableData['relationship_type'] = 'MANYTOONE';
             $tableData['junction_key_right'] = $tableData['column_name'];
         }
         $this->addVirtualColumn($tableName, $tableData);
     }
     return $tableData['column_name'];
 }