@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | |
| 40 | 40 | /** |
| 41 | 41 | * Method that extract the Api name |
| 42 | - * @return mixed |
|
| 42 | + * @return string |
|
| 43 | 43 | */ |
| 44 | 44 | public function getApi() |
| 45 | 45 | { |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | |
| 51 | 51 | /** |
| 52 | 52 | * Method that extract the Domain name |
| 53 | - * @return mixed |
|
| 53 | + * @return string |
|
| 54 | 54 | */ |
| 55 | 55 | public function getDomain() |
| 56 | 56 | { |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | * |
| 94 | 94 | * @param ModelCriteria $query |
| 95 | 95 | */ |
| 96 | - protected function joinTables(ModelCriteria &$query) |
|
| 96 | + protected function joinTables(ModelCriteria & $query) |
|
| 97 | 97 | { |
| 98 | 98 | //TODO for specific implementations |
| 99 | 99 | } |
@@ -106,14 +106,14 @@ discard block |
||
| 106 | 106 | */ |
| 107 | 107 | private function findPk(ModelCriteria $query, $pk) { |
| 108 | 108 | $pks = explode(Api::API_PK_SEPARATOR, urldecode($pk)); |
| 109 | - if(count($pks) == 1) { |
|
| 109 | + if (count($pks) == 1) { |
|
| 110 | 110 | return $query->findPk($pks[0]); |
| 111 | - } else { |
|
| 111 | + }else { |
|
| 112 | 112 | $i = 0; |
| 113 | - foreach($this->getPkDbName() as $key => $phpName) { |
|
| 113 | + foreach ($this->getPkDbName() as $key => $phpName) { |
|
| 114 | 114 | $query->filterBy($phpName, $pks[$i]); |
| 115 | 115 | $i++; |
| 116 | - if($i >= count($pks)) break; |
|
| 116 | + if ($i >= count($pks)) break; |
|
| 117 | 117 | } |
| 118 | 118 | return $query->findOne(); |
| 119 | 119 | } |
@@ -140,8 +140,8 @@ discard block |
||
| 140 | 140 | try { |
| 141 | 141 | $query = $this->prepareQuery(); |
| 142 | 142 | $this->model = $this->findPk($query, $pk); |
| 143 | - } catch (\Exception $e) { |
|
| 144 | - Logger::log(get_class($this) . ': ' . $e->getMessage(), LOG_ERR); |
|
| 143 | + }catch (\Exception $e) { |
|
| 144 | + Logger::log(get_class($this).': '.$e->getMessage(), LOG_ERR); |
|
| 145 | 145 | } |
| 146 | 146 | } |
| 147 | 147 | |
@@ -162,7 +162,7 @@ discard block |
||
| 162 | 162 | /** |
| 163 | 163 | * @param ModelCriteria $query |
| 164 | 164 | */ |
| 165 | - private function checkReturnFields(ModelCriteria &$query) |
|
| 165 | + private function checkReturnFields(ModelCriteria & $query) |
|
| 166 | 166 | { |
| 167 | 167 | $returnFields = Request::getInstance()->getQuery(Api::API_FIELDS_RESULT_FIELD); |
| 168 | 168 | if (null !== $returnFields) { |
@@ -113,7 +113,9 @@ |
||
| 113 | 113 | foreach($this->getPkDbName() as $key => $phpName) { |
| 114 | 114 | $query->filterBy($phpName, $pks[$i]); |
| 115 | 115 | $i++; |
| 116 | - if($i >= count($pks)) break; |
|
| 116 | + if($i >= count($pks)) { |
|
| 117 | + break; |
|
| 118 | + } |
|
| 117 | 119 | } |
| 118 | 120 | return $query->findOne(); |
| 119 | 121 | } |
@@ -48,7 +48,7 @@ |
||
| 48 | 48 | return ($aOrder < $bOrder) ? -1 : 1; |
| 49 | 49 | }); |
| 50 | 50 | $array['actions'] = []; |
| 51 | - foreach($this->actions as $action) { |
|
| 51 | + foreach ($this->actions as $action) { |
|
| 52 | 52 | $array['actions'][] = $action->__toArray(); |
| 53 | 53 | } |
| 54 | 54 | return $array; |
@@ -44,7 +44,7 @@ |
||
| 44 | 44 | header("Access-Control-Allow-Credentials: true"); |
| 45 | 45 | header("Access-Control-Allow-Origin: *"); |
| 46 | 46 | header("Access-Control-Allow-Methods: GET, POST, DELETE, PUT, PATCH, OPTIONS"); |
| 47 | - header("Access-Control-Allow-Headers: " . implode(', ', self::getCorsHeaders())); |
|
| 47 | + header("Access-Control-Allow-Headers: ".implode(', ', self::getCorsHeaders())); |
|
| 48 | 48 | } |
| 49 | 49 | if (Request::getInstance()->getMethod() == 'OPTIONS') { |
| 50 | 50 | Logger::log('Returning OPTIONS header confirmation for CORS pre flight requests', LOG_DEBUG); |
@@ -39,8 +39,8 @@ |
||
| 39 | 39 | "domain" => $this->getDomain(), |
| 40 | 40 | "listLabel" => Api::API_LIST_NAME_FIELD, |
| 41 | 41 | 'modelId' => Api::API_MODEL_KEY_FIELD, |
| 42 | - 'formUrl' => preg_replace('/\/\{(.*)\}$/i', '', $this->getRoute(strtolower('admin-api-form-' . $this->getDomain() . '-' . $this->getApi()), TRUE)), |
|
| 43 | - "url" => preg_replace('/\/\{(.*)\}$/i', '', $this->getRoute(strtolower($this->getDomain() . '-' . 'api-' . $this->getApi() . "-pk"), TRUE)), |
|
| 42 | + 'formUrl' => preg_replace('/\/\{(.*)\}$/i', '', $this->getRoute(strtolower('admin-api-form-'.$this->getDomain().'-'.$this->getApi()), TRUE)), |
|
| 43 | + "url" => preg_replace('/\/\{(.*)\}$/i', '', $this->getRoute(strtolower($this->getDomain().'-'.'api-'.$this->getApi()."-pk"), TRUE)), |
|
| 44 | 44 | ), [], ''); |
| 45 | 45 | } |
| 46 | 46 | |
@@ -3,7 +3,6 @@ |
||
| 3 | 3 | |
| 4 | 4 | use Propel\Runtime\ActiveQuery\ModelCriteria; |
| 5 | 5 | use Propel\Runtime\Map\TableMap; |
| 6 | -use PSFS\base\config\Config; |
|
| 7 | 6 | use PSFS\base\dto\JsonResponse; |
| 8 | 7 | use PSFS\base\dto\Order; |
| 9 | 8 | use PSFS\base\Logger; |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | * |
| 109 | 109 | * @param ModelCriteria $query |
| 110 | 110 | */ |
| 111 | - private function addOrders(ModelCriteria &$query) |
|
| 111 | + private function addOrders(ModelCriteria & $query) |
|
| 112 | 112 | { |
| 113 | 113 | $orderAdded = FALSE; |
| 114 | 114 | $tableMap = $this->getTableMap(); |
@@ -117,13 +117,13 @@ discard block |
||
| 117 | 117 | $orderAdded = TRUE; |
| 118 | 118 | if ($direction === Order::ASC) { |
| 119 | 119 | $query->addAscendingOrderByColumn($column->getPhpName()); |
| 120 | - } else { |
|
| 120 | + }else { |
|
| 121 | 121 | $query->addDescendingOrderByColumn($column->getPhpName()); |
| 122 | 122 | } |
| 123 | 123 | } |
| 124 | 124 | } |
| 125 | 125 | if (!$orderAdded) { |
| 126 | - foreach($this->getPkDbName() as $pk => $phpName) { |
|
| 126 | + foreach ($this->getPkDbName() as $pk => $phpName) { |
|
| 127 | 127 | $query->addAscendingOrderByColumn($pk); |
| 128 | 128 | } |
| 129 | 129 | } |
@@ -134,14 +134,14 @@ discard block |
||
| 134 | 134 | * |
| 135 | 135 | * @param ModelCriteria $query |
| 136 | 136 | */ |
| 137 | - private function addFilters(ModelCriteria &$query) |
|
| 137 | + private function addFilters(ModelCriteria & $query) |
|
| 138 | 138 | { |
| 139 | 139 | if (count($this->query) > 0) { |
| 140 | 140 | $tableMap = $this->getTableMap(); |
| 141 | 141 | foreach ($this->query as $field => $value) { |
| 142 | 142 | if (self::API_COMBO_FIELD === $field) { |
| 143 | 143 | ApiHelper::composerComboField($tableMap, $query, $this->extraColumns, $value); |
| 144 | - } elseif(!preg_match('/^__/', $field)) { |
|
| 144 | + } elseif (!preg_match('/^__/', $field)) { |
|
| 145 | 145 | ApiHelper::addModelField($tableMap, $query, $field, $value); |
| 146 | 146 | } |
| 147 | 147 | } |
@@ -162,10 +162,10 @@ discard block |
||
| 162 | 162 | list($page, $limit) = $this->extractPagination(); |
| 163 | 163 | if ($limit == -1) { |
| 164 | 164 | $this->list = $query->find($this->con); |
| 165 | - } else { |
|
| 165 | + }else { |
|
| 166 | 166 | $this->list = $query->paginate($page, $limit, $this->con); |
| 167 | 167 | } |
| 168 | - } catch (\Exception $e) { |
|
| 168 | + }catch (\Exception $e) { |
|
| 169 | 169 | Logger::log($e->getMessage(), LOG_ERR); |
| 170 | 170 | } |
| 171 | 171 | } |
@@ -184,7 +184,7 @@ discard block |
||
| 184 | 184 | $code = 200; |
| 185 | 185 | list($return, $total, $pages) = $this->getList(); |
| 186 | 186 | $message = null; |
| 187 | - if(!$total) { |
|
| 187 | + if (!$total) { |
|
| 188 | 188 | $message = _('No se han encontrado elementos para la búsqueda'); |
| 189 | 189 | } |
| 190 | 190 | |
@@ -210,7 +210,7 @@ discard block |
||
| 210 | 210 | $pages = 1; |
| 211 | 211 | $message = null; |
| 212 | 212 | list($code, $return) = $this->getSingleResult($pk); |
| 213 | - if($code !== 200) { |
|
| 213 | + if ($code !== 200) { |
|
| 214 | 214 | $message = _('No se ha encontrado el elemento solicitado'); |
| 215 | 215 | } |
| 216 | 216 | |
@@ -239,11 +239,11 @@ discard block |
||
| 239 | 239 | $status = 200; |
| 240 | 240 | $saved = TRUE; |
| 241 | 241 | $model = $this->model->toArray(); |
| 242 | - } else { |
|
| 242 | + }else { |
|
| 243 | 243 | $message = _('No se ha podido modificar el modelo seleccionado'); |
| 244 | 244 | } |
| 245 | - } catch (\Exception $e) { |
|
| 246 | - $message = _('Ha ocurrido un error intentando guardar el elemento: ') .'<br>'. $e->getMessage(); |
|
| 245 | + }catch (\Exception $e) { |
|
| 246 | + $message = _('Ha ocurrido un error intentando guardar el elemento: ').'<br>'.$e->getMessage(); |
|
| 247 | 247 | Logger::log($e->getMessage(), LOG_ERR); |
| 248 | 248 | } |
| 249 | 249 | |
@@ -277,14 +277,14 @@ discard block |
||
| 277 | 277 | $updated = TRUE; |
| 278 | 278 | $status = 200; |
| 279 | 279 | $model = $this->model->toArray(); |
| 280 | - } else { |
|
| 280 | + }else { |
|
| 281 | 281 | $message = _('Ha ocurrido un error intentando actualizar el elemento, por favor revisa los logs'); |
| 282 | 282 | } |
| 283 | - } catch (\Exception $e) { |
|
| 283 | + }catch (\Exception $e) { |
|
| 284 | 284 | $message = $e->getMessage(); |
| 285 | 285 | Logger::getInstance(get_class($this->model))->errorLog($e->getMessage()); |
| 286 | 286 | } |
| 287 | - } else { |
|
| 287 | + }else { |
|
| 288 | 288 | $message = _('No se ha encontrado el modelo al que se hace referencia para actualizar'); |
| 289 | 289 | } |
| 290 | 290 | |
@@ -314,7 +314,7 @@ discard block |
||
| 314 | 314 | $this->model->delete($this->con); |
| 315 | 315 | $deleted = TRUE; |
| 316 | 316 | } |
| 317 | - } catch (\Exception $e) { |
|
| 317 | + }catch (\Exception $e) { |
|
| 318 | 318 | $message = _('Ha ocurrido un error intentando eliminar el elemento, por favor verifica que no tenga otros elementos relacionados'); |
| 319 | 319 | Logger::getInstance(get_class($this->model))->errorLog($e->getMessage()); |
| 320 | 320 | } |
@@ -348,8 +348,8 @@ discard block |
||
| 348 | 348 | $total = $this->list->getNbResults(); |
| 349 | 349 | $pages = $this->list->getLastPage(); |
| 350 | 350 | } |
| 351 | - } catch (\Exception $e) { |
|
| 352 | - Logger::log(get_class($this) . ': ' . $e->getMessage(), LOG_ERR); |
|
| 351 | + }catch (\Exception $e) { |
|
| 352 | + Logger::log(get_class($this).': '.$e->getMessage(), LOG_ERR); |
|
| 353 | 353 | } |
| 354 | 354 | |
| 355 | 355 | return array($return, $total, $pages); |
@@ -367,7 +367,7 @@ discard block |
||
| 367 | 367 | $return = array(); |
| 368 | 368 | if (NULL === $model || !method_exists($model, 'toArray')) { |
| 369 | 369 | $code = 404; |
| 370 | - } else { |
|
| 370 | + }else { |
|
| 371 | 371 | $return = $model->toArray(); |
| 372 | 372 | } |
| 373 | 373 | |
@@ -6,7 +6,6 @@ |
||
| 6 | 6 | use Propel\Runtime\Propel; |
| 7 | 7 | use PSFS\base\config\Config; |
| 8 | 8 | use PSFS\base\Logger; |
| 9 | -use PSFS\base\types\traits\DebugTrait; |
|
| 10 | 9 | |
| 11 | 10 | /** |
| 12 | 11 | * Trait ConnectionTrait |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | protected function createConnection(TableMap $tableMap) |
| 27 | 27 | { |
| 28 | 28 | $this->con = Propel::getConnection($tableMap::DATABASE_NAME); |
| 29 | - if(method_exists($this->con, 'useDebug')) { |
|
| 29 | + if (method_exists($this->con, 'useDebug')) { |
|
| 30 | 30 | Logger::log('Enabling debug queries mode', LOG_INFO); |
| 31 | 31 | $this->con->useDebug(Config::getParam('debug')); |
| 32 | 32 | } |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | if (null !== $this->con && $this->con->inTransaction()) { |
| 44 | 44 | if ($status === 200) { |
| 45 | 45 | $this->con->commit(); |
| 46 | - } else { |
|
| 46 | + }else { |
|
| 47 | 47 | $this->con->rollBack(); |
| 48 | 48 | } |
| 49 | 49 | } |
@@ -58,21 +58,21 @@ discard block |
||
| 58 | 58 | if (count($pks) == 1) { |
| 59 | 59 | $pks = array_keys($pks); |
| 60 | 60 | return [ |
| 61 | - $tableMap::TABLE_NAME . '.' . $pks[0] => Api::API_MODEL_KEY_FIELD |
|
| 61 | + $tableMap::TABLE_NAME.'.'.$pks[0] => Api::API_MODEL_KEY_FIELD |
|
| 62 | 62 | ]; |
| 63 | 63 | } elseif (count($pks) > 1) { |
| 64 | 64 | $apiPks = []; |
| 65 | 65 | $principal = ''; |
| 66 | 66 | $sep = 'CONCAT('; |
| 67 | 67 | foreach ($pks as $pk) { |
| 68 | - $apiPks[$tableMap::TABLE_NAME . '.' . $pk->getName()] = $pk->getPhpName(); |
|
| 69 | - $principal .= $sep . $tableMap::TABLE_NAME . '.' . $pk->getName(); |
|
| 70 | - $sep = ', "' . Api::API_PK_SEPARATOR . '", '; |
|
| 68 | + $apiPks[$tableMap::TABLE_NAME.'.'.$pk->getName()] = $pk->getPhpName(); |
|
| 69 | + $principal .= $sep.$tableMap::TABLE_NAME.'.'.$pk->getName(); |
|
| 70 | + $sep = ', "'.Api::API_PK_SEPARATOR.'", '; |
|
| 71 | 71 | } |
| 72 | 72 | $principal .= ')'; |
| 73 | 73 | $apiPks[$principal] = Api::API_MODEL_KEY_FIELD; |
| 74 | 74 | return $apiPks; |
| 75 | - } else { |
|
| 75 | + }else { |
|
| 76 | 76 | throw new ApiException(_('El modelo de la API no está debidamente mapeado, no hay Primary Key o es compuesta')); |
| 77 | 77 | } |
| 78 | 78 | } |
@@ -95,10 +95,10 @@ discard block |
||
| 95 | 95 | $pks = ''; |
| 96 | 96 | $sep = ''; |
| 97 | 97 | foreach ($tableMap->getPrimaryKeys() as $pk) { |
| 98 | - $pks .= $sep . $pk->getFullyQualifiedName(); |
|
| 98 | + $pks .= $sep.$pk->getFullyQualifiedName(); |
|
| 99 | 99 | $sep = ', "|", '; |
| 100 | 100 | } |
| 101 | - $this->extraColumns['CONCAT("' . $tableMap->getPhpName() . ' #", ' . $pks . ')'] = Api::API_LIST_NAME_FIELD; |
|
| 101 | + $this->extraColumns['CONCAT("'.$tableMap->getPhpName().' #", '.$pks.')'] = Api::API_LIST_NAME_FIELD; |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | /** |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | } |
| 121 | 121 | if (null !== $column) { |
| 122 | 122 | $this->extraColumns[$column->getFullyQualifiedName()] = Api::API_LIST_NAME_FIELD; |
| 123 | - } else { |
|
| 123 | + }else { |
|
| 124 | 124 | $this->addClassListName($tableMap); |
| 125 | 125 | } |
| 126 | 126 | } |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | * @param ModelCriteria $query |
| 133 | 133 | * @param string $action |
| 134 | 134 | */ |
| 135 | - private function addExtraColumns(ModelCriteria &$query, $action) |
|
| 135 | + private function addExtraColumns(ModelCriteria & $query, $action) |
|
| 136 | 136 | { |
| 137 | 137 | if (Api::API_ACTION_LIST === $action) { |
| 138 | 138 | $this->addDefaultListField(); |
@@ -160,21 +160,21 @@ discard block |
||
| 160 | 160 | /** |
| 161 | 161 | * @param ModelCriteria $query |
| 162 | 162 | */ |
| 163 | - protected function checkI18n(ModelCriteria &$query) |
|
| 163 | + protected function checkI18n(ModelCriteria & $query) |
|
| 164 | 164 | { |
| 165 | 165 | $model = $this->getModelNamespace(); |
| 166 | - $modelI18n = $model . 'I18n'; |
|
| 166 | + $modelI18n = $model.'I18n'; |
|
| 167 | 167 | if (method_exists($query, 'useI18nQuery')) { |
| 168 | 168 | $default_language = explode('_', Config::getParam('default.language', 'es_ES')); |
| 169 | 169 | $query->useI18nQuery(Request::header('X-API-LANG', $default_language[0])); |
| 170 | - $modelI18nTableMapClass = str_replace('\\Models\\', '\\Models\\Map\\', $modelI18n) . 'TableMap'; |
|
| 170 | + $modelI18nTableMapClass = str_replace('\\Models\\', '\\Models\\Map\\', $modelI18n).'TableMap'; |
|
| 171 | 171 | /** @var TableMap $modelI18nTableMap */ |
| 172 | 172 | $modelI18nTableMap = $modelI18nTableMapClass::getTableMap(); |
| 173 | - foreach($modelI18nTableMap->getColumns() as $columnMap) { |
|
| 174 | - if(!$columnMap->isPrimaryKey()) { |
|
| 175 | - $query->withColumn($modelI18nTableMapClass::TABLE_NAME . '.' . $columnMap->getName(), $columnMap->getPhpName()); |
|
| 176 | - } elseif(!$columnMap->isForeignKey()) { |
|
| 177 | - $query->withColumn('IFNULL(' . $modelI18nTableMapClass::TABLE_NAME . '.' . $columnMap->getName() . ', "'.Request::header('X-API-LANG', 'es').'")', $columnMap->getPhpName()); |
|
| 173 | + foreach ($modelI18nTableMap->getColumns() as $columnMap) { |
|
| 174 | + if (!$columnMap->isPrimaryKey()) { |
|
| 175 | + $query->withColumn($modelI18nTableMapClass::TABLE_NAME.'.'.$columnMap->getName(), $columnMap->getPhpName()); |
|
| 176 | + } elseif (!$columnMap->isForeignKey()) { |
|
| 177 | + $query->withColumn('IFNULL('.$modelI18nTableMapClass::TABLE_NAME.'.'.$columnMap->getName().', "'.Request::header('X-API-LANG', 'es').'")', $columnMap->getPhpName()); |
|
| 178 | 178 | } |
| 179 | 179 | } |
| 180 | 180 | } |
@@ -184,23 +184,23 @@ discard block |
||
| 184 | 184 | * @param ActiveRecordInterface $model |
| 185 | 185 | * @param array $data |
| 186 | 186 | */ |
| 187 | - protected function hydrateModelFromRequest(ActiveRecordInterface &$model, array $data = []) { |
|
| 187 | + protected function hydrateModelFromRequest(ActiveRecordInterface & $model, array $data = []) { |
|
| 188 | 188 | $model->fromArray($data); |
| 189 | 189 | $tableMap = $this->getTableMap(); |
| 190 | 190 | try { |
| 191 | - $relateI18n = $tableMap->getRelation($tableMap->getPhpName() . 'I18n'); |
|
| 192 | - if(null !== $relateI18n) { |
|
| 191 | + $relateI18n = $tableMap->getRelation($tableMap->getPhpName().'I18n'); |
|
| 192 | + if (null !== $relateI18n) { |
|
| 193 | 193 | $i18NTableMap = $relateI18n->getLocalTable(); |
| 194 | - foreach($i18NTableMap->getColumns() as $columnMap) { |
|
| 195 | - $method = 'set' . $columnMap->getPhpName(); |
|
| 196 | - if(!($columnMap->isPrimaryKey() && $columnMap->isForeignKey()) |
|
| 194 | + foreach ($i18NTableMap->getColumns() as $columnMap) { |
|
| 195 | + $method = 'set'.$columnMap->getPhpName(); |
|
| 196 | + if (!($columnMap->isPrimaryKey() && $columnMap->isForeignKey()) |
|
| 197 | 197 | &&array_key_exists($columnMap->getPhpName(), $data) |
| 198 | 198 | && method_exists($model, $method)) { |
| 199 | 199 | $model->$method($data[$columnMap->getPhpName()]); |
| 200 | 200 | } |
| 201 | 201 | } |
| 202 | 202 | } |
| 203 | - } catch(\Exception $e) { |
|
| 203 | + }catch (\Exception $e) { |
|
| 204 | 204 | Logger::log($e->getMessage(), LOG_WARNING); |
| 205 | 205 | } |
| 206 | 206 | } |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | session_start(); |
| 73 | 73 | } |
| 74 | 74 | // Fix for phpunits |
| 75 | - if(!isset($_SESSION)) { |
|
| 75 | + if (!isset($_SESSION)) { |
|
| 76 | 76 | $_SESSION = []; |
| 77 | 77 | } |
| 78 | 78 | } |
@@ -132,12 +132,12 @@ discard block |
||
| 132 | 132 | { |
| 133 | 133 | $saved = true; |
| 134 | 134 | try { |
| 135 | - $admins = Cache::getInstance()->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . 'admins.json', Cache::JSONGZ, true) ?: []; |
|
| 136 | - $admins[$user['username']]['hash'] = sha1($user['username'] . $user['password']); |
|
| 135 | + $admins = Cache::getInstance()->getDataFromFile(CONFIG_DIR.DIRECTORY_SEPARATOR.'admins.json', Cache::JSONGZ, true) ?: []; |
|
| 136 | + $admins[$user['username']]['hash'] = sha1($user['username'].$user['password']); |
|
| 137 | 137 | $admins[$user['username']]['profile'] = $user['profile']; |
| 138 | 138 | |
| 139 | - Cache::getInstance()->storeData(CONFIG_DIR . DIRECTORY_SEPARATOR . 'admins.json', $admins, Cache::JSONGZ, true); |
|
| 140 | - } catch(\Exception $e) { |
|
| 139 | + Cache::getInstance()->storeData(CONFIG_DIR.DIRECTORY_SEPARATOR.'admins.json', $admins, Cache::JSONGZ, true); |
|
| 140 | + }catch (\Exception $e) { |
|
| 141 | 141 | Logger::log($e->getMessage(), LOG_ERR); |
| 142 | 142 | $saved = false; |
| 143 | 143 | } |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | */ |
| 175 | 175 | public function getAdmins() |
| 176 | 176 | { |
| 177 | - return Cache::getInstance()->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . 'admins.json', Cache::JSONGZ, true); |
|
| 177 | + return Cache::getInstance()->getDataFromFile(CONFIG_DIR.DIRECTORY_SEPARATOR.'admins.json', Cache::JSONGZ, true); |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | /** |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | } |
| 203 | 203 | if (!empty($user) && !empty($admins[$user])) { |
| 204 | 204 | $auth = $admins[$user]['hash']; |
| 205 | - $this->authorized = ($auth == sha1($user . $pass)); |
|
| 205 | + $this->authorized = ($auth == sha1($user.$pass)); |
|
| 206 | 206 | if ($this->authorized) { |
| 207 | 207 | $this->admin = array( |
| 208 | 208 | 'alias' => $user, |
@@ -42,7 +42,7 @@ |
||
| 42 | 42 | $this->success = $result; |
| 43 | 43 | $this->total = $total ?: count($data); |
| 44 | 44 | $this->pages = $pages; |
| 45 | - if(null !== $message) { |
|
| 45 | + if (null !== $message) { |
|
| 46 | 46 | $this->message = $message; |
| 47 | 47 | } |
| 48 | 48 | } |