@@ -30,8 +30,9 @@ |
||
| 30 | 30 | switch ($method) |
| 31 | 31 | { |
| 32 | 32 | case '_COOKIE': |
| 33 | - if (array_key_exists($key, $_COOKIE) || !empty($_COOKIE[$key])) |
|
| 34 | - setcookie($key, $_COOKIE[$key], time() - 1, '/'); |
|
| 33 | + if (array_key_exists($key, $_COOKIE) || !empty($_COOKIE[$key])) { |
|
| 34 | + setcookie($key, $_COOKIE[$key], time() - 1, '/'); |
|
| 35 | + } |
|
| 35 | 36 | break; |
| 36 | 37 | |
| 37 | 38 | case '_SESSION': |
@@ -21,9 +21,10 @@ |
||
| 21 | 21 | $db->setDbuser($user); |
| 22 | 22 | $db->setDbpass($pass); |
| 23 | 23 | |
| 24 | - if ($db->isConnected()) |
|
| 25 | - return $db->reconnect() |
|
| 24 | + if ($db->isConnected()) { |
|
| 25 | + return $db->reconnect() |
|
| 26 | 26 | else |
| 27 | 27 | return $db->connect(); |
| 28 | + } |
|
| 28 | 29 | } |
| 29 | 30 | } |
| 30 | 31 | \ No newline at end of file |
@@ -26,8 +26,9 @@ discard block |
||
| 26 | 26 | |
| 27 | 27 | foreach ($files as $file) |
| 28 | 28 | { |
| 29 | - if (!in_array($file, ['.', '..'])) |
|
| 30 | - $_files[] = $file; |
|
| 29 | + if (!in_array($file, ['.', '..'])) { |
|
| 30 | + $_files[] = $file; |
|
| 31 | + } |
|
| 31 | 32 | } |
| 32 | 33 | |
| 33 | 34 | $_folders[$folder] = $_files; |
@@ -74,8 +75,9 @@ discard block |
||
| 74 | 75 | |
| 75 | 76 | private function object_to_array($obj) |
| 76 | 77 | { |
| 77 | - if (is_object($obj)) |
|
| 78 | - $obj = (array) $obj; |
|
| 78 | + if (is_object($obj)) { |
|
| 79 | + $obj = (array) $obj; |
|
| 80 | + } |
|
| 79 | 81 | |
| 80 | 82 | if (is_array($obj)) |
| 81 | 83 | { |
@@ -85,9 +87,9 @@ discard block |
||
| 85 | 87 | { |
| 86 | 88 | $new[$key] = $this->object_to_array($val); |
| 87 | 89 | } |
| 90 | + } else { |
|
| 91 | + $new = $obj; |
|
| 88 | 92 | } |
| 89 | - else |
|
| 90 | - $new = $obj; |
|
| 91 | 93 | |
| 92 | 94 | return $new; |
| 93 | 95 | } |
@@ -85,8 +85,9 @@ discard block |
||
| 85 | 85 | */ |
| 86 | 86 | private function getUsersEntity() |
| 87 | 87 | { |
| 88 | - if (!is_null($this->usersEntity)) |
|
| 89 | - return $this->usersEntity; |
|
| 88 | + if (!is_null($this->usersEntity)) { |
|
| 89 | + return $this->usersEntity; |
|
| 90 | + } |
|
| 90 | 91 | |
| 91 | 92 | $this->usersEntity = new EntityAdapter(new TableGateway(new UserModel())); |
| 92 | 93 | |
@@ -98,8 +99,9 @@ discard block |
||
| 98 | 99 | */ |
| 99 | 100 | private function getConnectionTypesEntity() |
| 100 | 101 | { |
| 101 | - if (!is_null($this->connectionTypesEntity)) |
|
| 102 | - return $this->connectionTypesEntity; |
|
| 102 | + if (!is_null($this->connectionTypesEntity)) { |
|
| 103 | + return $this->connectionTypesEntity; |
|
| 104 | + } |
|
| 103 | 105 | |
| 104 | 106 | $this->connectionTypesEntity = new EntityAdapter(new TableGateway(new ConnectionType())); |
| 105 | 107 | |
@@ -111,8 +113,9 @@ discard block |
||
| 111 | 113 | */ |
| 112 | 114 | private function getConnectionFieldsEntity() |
| 113 | 115 | { |
| 114 | - if (!is_null($this->connectionFieldsEntity)) |
|
| 115 | - return $this->connectionFieldsEntity; |
|
| 116 | + if (!is_null($this->connectionFieldsEntity)) { |
|
| 117 | + return $this->connectionFieldsEntity; |
|
| 118 | + } |
|
| 116 | 119 | |
| 117 | 120 | $this->connectionFieldsEntity = new EntityAdapter(new TableGateway(new ConnectionTypeField())); |
| 118 | 121 | |
@@ -124,8 +127,9 @@ discard block |
||
| 124 | 127 | */ |
| 125 | 128 | private function getUserConnectionEntity() |
| 126 | 129 | { |
| 127 | - if (!is_null($this->userConnectionEntity)) |
|
| 128 | - return $this->userConnectionEntity; |
|
| 130 | + if (!is_null($this->userConnectionEntity)) { |
|
| 131 | + return $this->userConnectionEntity; |
|
| 132 | + } |
|
| 129 | 133 | |
| 130 | 134 | $this->userConnectionEntity = new EntityAdapter(new UserConnectionsTable(new UserConnection())); |
| 131 | 135 | |
@@ -137,8 +141,9 @@ discard block |
||
| 137 | 141 | */ |
| 138 | 142 | private function getUserConnectionDetailsEntity() |
| 139 | 143 | { |
| 140 | - if (!is_null($this->userConnectionDetailsEntity)) |
|
| 141 | - return $this->userConnectionDetailsEntity; |
|
| 144 | + if (!is_null($this->userConnectionDetailsEntity)) { |
|
| 145 | + return $this->userConnectionDetailsEntity; |
|
| 146 | + } |
|
| 142 | 147 | |
| 143 | 148 | $this->userConnectionDetailsEntity = new EntityAdapter(new TableGateway(new UserConnectionDetails())); |
| 144 | 149 | |
@@ -177,14 +182,12 @@ discard block |
||
| 177 | 182 | |
| 178 | 183 | # SUCCESS-MESSAGE |
| 179 | 184 | $data["process"] = "success"; |
| 180 | - } |
|
| 181 | - catch (\Drone\Exception\Exception $e) |
|
| 185 | + } catch (\Drone\Exception\Exception $e) |
|
| 182 | 186 | { |
| 183 | 187 | # ERROR-MESSAGE |
| 184 | 188 | $data["process"] = "warning"; |
| 185 | 189 | $data["message"] = $e->getMessage(); |
| 186 | - } |
|
| 187 | - catch (\Exception $e) |
|
| 190 | + } catch (\Exception $e) |
|
| 188 | 191 | { |
| 189 | 192 | $file = str_replace('\\', '', __CLASS__); |
| 190 | 193 | $storage = new \Drone\Exception\Storage("cache/$file.json"); |
@@ -289,13 +292,15 @@ discard block |
||
| 289 | 292 | "USER_CONN_ID" => $post["id"] |
| 290 | 293 | ]); |
| 291 | 294 | |
| 292 | - if (!count($connection)) |
|
| 293 | - throw new \Exception("The Connection does not exists"); |
|
| 295 | + if (!count($connection)) { |
|
| 296 | + throw new \Exception("The Connection does not exists"); |
|
| 297 | + } |
|
| 294 | 298 | |
| 295 | 299 | $connection = array_shift($connection); |
| 296 | 300 | |
| 297 | - if ($connection->STATE == 'I') |
|
| 298 | - throw new \Drone\Exception\Exception("This connection was deleted", 300); |
|
| 301 | + if ($connection->STATE == 'I') { |
|
| 302 | + throw new \Drone\Exception\Exception("This connection was deleted", 300); |
|
| 303 | + } |
|
| 299 | 304 | |
| 300 | 305 | $connection->exchangeArray([ |
| 301 | 306 | "STATE" => 'I' |
@@ -309,14 +314,12 @@ discard block |
||
| 309 | 314 | |
| 310 | 315 | # SUCCESS-MESSAGE |
| 311 | 316 | $data["process"] = "success"; |
| 312 | - } |
|
| 313 | - catch (\Drone\Exception\Exception $e) |
|
| 317 | + } catch (\Drone\Exception\Exception $e) |
|
| 314 | 318 | { |
| 315 | 319 | # ERROR-MESSAGE |
| 316 | 320 | $data["process"] = "warning"; |
| 317 | 321 | $data["message"] = $e->getMessage(); |
| 318 | - } |
|
| 319 | - catch (\Exception $e) |
|
| 322 | + } catch (\Exception $e) |
|
| 320 | 323 | { |
| 321 | 324 | $file = str_replace('\\', '', __CLASS__); |
| 322 | 325 | $storage = new \Drone\Exception\Storage("cache/$file.json"); |
@@ -387,8 +390,7 @@ discard block |
||
| 387 | 390 | |
| 388 | 391 | # SUCCESS-MESSAGE |
| 389 | 392 | $data["process"] = "register-form"; |
| 390 | - } |
|
| 391 | - else if ($this->isPost()) |
|
| 393 | + } else if ($this->isPost()) |
|
| 392 | 394 | { |
| 393 | 395 | # STANDARD VALIDATIONS [check needed arguments] |
| 394 | 396 | $needles = ['field', 'type', 'aliasname']; |
@@ -486,22 +488,19 @@ discard block |
||
| 486 | 488 | |
| 487 | 489 | # SUCCESS-MESSAGE |
| 488 | 490 | $data["process"] = "process-response"; |
| 489 | - } |
|
| 490 | - else |
|
| 491 | + } else |
|
| 491 | 492 | { |
| 492 | 493 | $http = new Http(); |
| 493 | 494 | $http->writeStatus($http::HTTP_METHOD_NOT_ALLOWED); |
| 494 | 495 | |
| 495 | 496 | die('Error ' . $http::HTTP_METHOD_NOT_ALLOWED .' (' . $http->getStatusText($http::HTTP_METHOD_NOT_ALLOWED) . ')!!'); |
| 496 | 497 | } |
| 497 | - } |
|
| 498 | - catch (\Drone\Exception\Exception $e) |
|
| 498 | + } catch (\Drone\Exception\Exception $e) |
|
| 499 | 499 | { |
| 500 | 500 | # ERROR-MESSAGE |
| 501 | 501 | $data["process"] = "warning"; |
| 502 | 502 | $data["message"] = $e->getMessage(); |
| 503 | - } |
|
| 504 | - catch (\Exception $e) |
|
| 503 | + } catch (\Exception $e) |
|
| 505 | 504 | { |
| 506 | 505 | $file = str_replace('\\', '', __CLASS__); |
| 507 | 506 | $storage = new \Drone\Exception\Storage("cache/$file.json"); |
@@ -588,13 +587,15 @@ discard block |
||
| 588 | 587 | "USER_CONN_ID" => $get["id"] |
| 589 | 588 | ]); |
| 590 | 589 | |
| 591 | - if (!count($connection)) |
|
| 592 | - throw new \Exception("The Connection does not exists"); |
|
| 590 | + if (!count($connection)) { |
|
| 591 | + throw new \Exception("The Connection does not exists"); |
|
| 592 | + } |
|
| 593 | 593 | |
| 594 | 594 | $connection = array_shift($connection); |
| 595 | 595 | |
| 596 | - if ($connection->STATE == 'I') |
|
| 597 | - throw new \Drone\Exception\Exception("This connection was deleted", 300); |
|
| 596 | + if ($connection->STATE == 'I') { |
|
| 597 | + throw new \Drone\Exception\Exception("This connection was deleted", 300); |
|
| 598 | + } |
|
| 598 | 599 | |
| 599 | 600 | $connection_details = $this->getUserConnectionDetailsEntity()->select([ |
| 600 | 601 | "USER_CONN_ID" => $get["id"] |
@@ -612,8 +613,7 @@ discard block |
||
| 612 | 613 | |
| 613 | 614 | # SUCCESS-MESSAGE |
| 614 | 615 | $data["process"] = "update-form"; |
| 615 | - } |
|
| 616 | - else if ($this->isPost()) |
|
| 616 | + } else if ($this->isPost()) |
|
| 617 | 617 | { |
| 618 | 618 | # STANDARD VALIDATIONS [check needed arguments] |
| 619 | 619 | $needles = ['_conn_id', 'type', 'aliasname']; |
@@ -685,13 +685,15 @@ discard block |
||
| 685 | 685 | "USER_CONN_ID" => $post["_conn_id"], |
| 686 | 686 | ]); |
| 687 | 687 | |
| 688 | - if (!count($userConnection)) |
|
| 689 | - throw new \Exception("The Connection does not exists"); |
|
| 688 | + if (!count($userConnection)) { |
|
| 689 | + throw new \Exception("The Connection does not exists"); |
|
| 690 | + } |
|
| 690 | 691 | |
| 691 | 692 | $userConnection = array_shift($userConnection); |
| 692 | 693 | |
| 693 | - if ($userConnection->STATE == 'I') |
|
| 694 | - throw new \Drone\Exception\Exception("This connection was deleted", 300); |
|
| 694 | + if ($userConnection->STATE == 'I') { |
|
| 695 | + throw new \Drone\Exception\Exception("This connection was deleted", 300); |
|
| 696 | + } |
|
| 695 | 697 | |
| 696 | 698 | $userConnection->exchangeArray([ |
| 697 | 699 | "CONN_TYPE_ID" => $post["type"], |
@@ -723,22 +725,19 @@ discard block |
||
| 723 | 725 | |
| 724 | 726 | # SUCCESS-MESSAGE |
| 725 | 727 | $data["process"] = "process-response"; |
| 726 | - } |
|
| 727 | - else |
|
| 728 | + } else |
|
| 728 | 729 | { |
| 729 | 730 | $http = new Http(); |
| 730 | 731 | $http->writeStatus($http::HTTP_METHOD_NOT_ALLOWED); |
| 731 | 732 | |
| 732 | 733 | die('Error ' . $http::HTTP_METHOD_NOT_ALLOWED .' (' . $http->getStatusText($http::HTTP_METHOD_NOT_ALLOWED) . ')!!'); |
| 733 | 734 | } |
| 734 | - } |
|
| 735 | - catch (\Drone\Exception\Exception $e) |
|
| 735 | + } catch (\Drone\Exception\Exception $e) |
|
| 736 | 736 | { |
| 737 | 737 | # ERROR-MESSAGE |
| 738 | 738 | $data["process"] = "warning"; |
| 739 | 739 | $data["message"] = $e->getMessage(); |
| 740 | - } |
|
| 741 | - catch (\Exception $e) |
|
| 740 | + } catch (\Exception $e) |
|
| 742 | 741 | { |
| 743 | 742 | $file = str_replace('\\', '', __CLASS__); |
| 744 | 743 | $storage = new \Drone\Exception\Storage("cache/$file.json"); |
@@ -786,15 +785,16 @@ discard block |
||
| 786 | 785 | if (!$hd || !@fwrite($hd, $errorInformation)) |
| 787 | 786 | { |
| 788 | 787 | # error storing are not mandatory! |
| 788 | + } else { |
|
| 789 | + @fclose($hd); |
|
| 789 | 790 | } |
| 790 | - else |
|
| 791 | - @fclose($hd); |
|
| 792 | 791 | |
| 793 | 792 | $config = include 'config/application.config.php'; |
| 794 | 793 | $dev = $config["environment"]["dev_mode"]; |
| 795 | 794 | |
| 796 | - if ($dev) |
|
| 797 | - echo $errorInformation; |
|
| 795 | + if ($dev) { |
|
| 796 | + echo $errorInformation; |
|
| 797 | + } |
|
| 798 | 798 | } |
| 799 | 799 | } |
| 800 | 800 | } |
| 801 | 801 | \ No newline at end of file |
@@ -15,23 +15,25 @@ |
||
| 15 | 15 | { |
| 16 | 16 | if (is_array($in)) |
| 17 | 17 | { |
| 18 | - if (array_key_exists($key, $in)) |
|
| 19 | - $in = $in[$key]; |
|
| 20 | - else |
|
| 21 | - return $value; |
|
| 18 | + if (array_key_exists($key, $in)) { |
|
| 19 | + $in = $in[$key]; |
|
| 20 | + } else { |
|
| 21 | + return $value; |
|
| 22 | + } |
|
| 23 | + } else { |
|
| 24 | + return $value; |
|
| 22 | 25 | } |
| 23 | - else |
|
| 24 | - return $value; |
|
| 25 | 26 | |
| 26 | 27 | $key = ($array) ? array_shift($array) : NULL; |
| 27 | 28 | |
| 28 | - if (!$key) |
|
| 29 | - return $in; |
|
| 29 | + if (!$key) { |
|
| 30 | + return $in; |
|
| 31 | + } |
|
| 30 | 32 | |
| 31 | 33 | } while($key); |
| 34 | + } else { |
|
| 35 | + return $value; |
|
| 32 | 36 | } |
| 33 | - else |
|
| 34 | - return $value; |
|
| 35 | 37 | } |
| 36 | 38 | } |
| 37 | 39 | |
@@ -24,8 +24,9 @@ discard block |
||
| 24 | 24 | */ |
| 25 | 25 | private function getUserAdapter() |
| 26 | 26 | { |
| 27 | - if (!is_null($this->userAdapter)) |
|
| 28 | - return $this->userAdapter; |
|
| 27 | + if (!is_null($this->userAdapter)) { |
|
| 28 | + return $this->userAdapter; |
|
| 29 | + } |
|
| 29 | 30 | |
| 30 | 31 | $this->userAdapter = new EntityAdapter(new UserTbl(new User())); |
| 31 | 32 | |
@@ -48,8 +49,9 @@ discard block |
||
| 48 | 49 | * when users log in. It should be an unique session id for the app to prevent bad redirections with other projects. |
| 49 | 50 | */ |
| 50 | 51 | # save only no XmlHttpRequest! |
| 51 | - if (!$c->isXmlHttpRequest()) |
|
| 52 | - $_SESSION["last_uri_" . $global_config["project"]["id"]] = $_SERVER["REQUEST_URI"]; |
|
| 52 | + if (!$c->isXmlHttpRequest()) { |
|
| 53 | + $_SESSION["last_uri_" . $global_config["project"]["id"]] = $_SERVER["REQUEST_URI"]; |
|
| 54 | + } |
|
| 53 | 55 | |
| 54 | 56 | # config constraints |
| 55 | 57 | $components = [ |
@@ -133,9 +135,9 @@ discard block |
||
| 133 | 135 | $c->stopExecution(false); |
| 134 | 136 | |
| 135 | 137 | header("location: " . $c->getBasePath() . "/public/" . $redirect); |
| 138 | + } else { |
|
| 139 | + $username_credential = $_COOKIE[$key]; |
|
| 136 | 140 | } |
| 137 | - else |
|
| 138 | - $username_credential = $_COOKIE[$key]; |
|
| 139 | 141 | |
| 140 | 142 | break; |
| 141 | 143 | |
@@ -147,9 +149,9 @@ discard block |
||
| 147 | 149 | $c->stopExecution(false); |
| 148 | 150 | |
| 149 | 151 | header("location: " . $c->getBasePath() . "/public/" . $redirect); |
| 152 | + } else { |
|
| 153 | + $username_credential = $_SESSION[$key]; |
|
| 150 | 154 | } |
| 151 | - else |
|
| 152 | - $username_credential = $_SESSION[$key]; |
|
| 153 | 155 | |
| 154 | 156 | break; |
| 155 | 157 | } |
@@ -161,10 +163,10 @@ discard block |
||
| 161 | 163 | $state_field = $config["authentication"]["gateway"]["table_info"]["columns"]["state_field"]; |
| 162 | 164 | $active_state = $config["authentication"]["gateway"]["table_info"]["column_values"]["state_field"]["user_active"]; |
| 163 | 165 | |
| 164 | - if ($user->{$state_field} != $active_state) |
|
| 165 | - throw new \Exception("The user has been inactived!. Please log-in again."); |
|
| 166 | - } |
|
| 167 | - catch (\Exception $e) |
|
| 166 | + if ($user->{$state_field} != $active_state) { |
|
| 167 | + throw new \Exception("The user has been inactived!. Please log-in again."); |
|
| 168 | + } |
|
| 169 | + } catch (\Exception $e) |
|
| 168 | 170 | { |
| 169 | 171 | $file = str_replace('\\', '', __CLASS__); |
| 170 | 172 | $storage = new \Drone\Exception\Storage("cache/$file.json"); |
@@ -194,10 +196,11 @@ discard block |
||
| 194 | 196 | $layoutManager->setParams($data); |
| 195 | 197 | |
| 196 | 198 | # for AJAX requests! |
| 197 | - if ($c->isXmlHttpRequest()) |
|
| 198 | - $layoutManager->content(); |
|
| 199 | - else |
|
| 200 | - $layoutManager->fromTemplate($this, 'blank'); |
|
| 199 | + if ($c->isXmlHttpRequest()) { |
|
| 200 | + $layoutManager->content(); |
|
| 201 | + } else { |
|
| 202 | + $layoutManager->fromTemplate($this, 'blank'); |
|
| 203 | + } |
|
| 201 | 204 | } |
| 202 | 205 | } |
| 203 | 206 | |
@@ -207,8 +210,9 @@ discard block |
||
| 207 | 210 | |
| 208 | 211 | if (array_key_exists('locale', $_GET)) |
| 209 | 212 | { |
| 210 | - if (in_array($_GET['locale'], ['en', 'es', 'fr'])) |
|
| 211 | - $_SESSION["LOCALE"] = $_GET['locale']; |
|
| 213 | + if (in_array($_GET['locale'], ['en', 'es', 'fr'])) { |
|
| 214 | + $_SESSION["LOCALE"] = $_GET['locale']; |
|
| 215 | + } |
|
| 212 | 216 | } |
| 213 | 217 | |
| 214 | 218 | $locale = (array_key_exists('LOCALE', $_SESSION)) ? $_SESSION["LOCALE"] : $config["environment"]["locale"]; |
@@ -49,8 +49,9 @@ discard block |
||
| 49 | 49 | |
| 50 | 50 | foreach ($row as $key => $value) |
| 51 | 51 | { |
| 52 | - if (is_string($key)) |
|
| 53 | - $filtered_array[$key] = $value; |
|
| 52 | + if (is_string($key)) { |
|
| 53 | + $filtered_array[$key] = $value; |
|
| 54 | + } |
|
| 54 | 55 | } |
| 55 | 56 | |
| 56 | 57 | $user = new User(); |
@@ -81,8 +82,9 @@ discard block |
||
| 81 | 82 | |
| 82 | 83 | foreach ($row as $key => $value) |
| 83 | 84 | { |
| 84 | - if (is_string($key)) |
|
| 85 | - $filtered_array[$key] = $value; |
|
| 85 | + if (is_string($key)) { |
|
| 86 | + $filtered_array[$key] = $value; |
|
| 87 | + } |
|
| 86 | 88 | } |
| 87 | 89 | |
| 88 | 90 | $user = new User(); |
@@ -39,8 +39,9 @@ discard block |
||
| 39 | 39 | */ |
| 40 | 40 | private function getUserAdapter() |
| 41 | 41 | { |
| 42 | - if (!is_null($this->userAdapter)) |
|
| 43 | - return $this->userAdapter; |
|
| 42 | + if (!is_null($this->userAdapter)) { |
|
| 43 | + return $this->userAdapter; |
|
| 44 | + } |
|
| 44 | 45 | |
| 45 | 46 | $this->userAdapter = new EntityAdapter(new TableGateway(new User())); |
| 46 | 47 | |
@@ -52,8 +53,9 @@ discard block |
||
| 52 | 53 | */ |
| 53 | 54 | private function getUserRoleAdapter() |
| 54 | 55 | { |
| 55 | - if (!is_null($this->userRoleAdapter)) |
|
| 56 | - return $this->userRoleAdapter; |
|
| 56 | + if (!is_null($this->userRoleAdapter)) { |
|
| 57 | + return $this->userRoleAdapter; |
|
| 58 | + } |
|
| 57 | 59 | |
| 58 | 60 | $this->userRoleAdapter = new EntityAdapter(new TableGateway(new UserRole())); |
| 59 | 61 | |
@@ -65,8 +67,9 @@ discard block |
||
| 65 | 67 | */ |
| 66 | 68 | private function getDbUserRoleAdapter() |
| 67 | 69 | { |
| 68 | - if (!is_null($this->dbUserRoleAdapter)) |
|
| 69 | - return $this->dbUserRoleAdapter; |
|
| 70 | + if (!is_null($this->dbUserRoleAdapter)) { |
|
| 71 | + return $this->dbUserRoleAdapter; |
|
| 72 | + } |
|
| 70 | 73 | |
| 71 | 74 | $this->dbUserRoleAdapter = new EntityAdapter(new TableGateway(new DbUserRole())); |
| 72 | 75 | |
@@ -95,24 +98,27 @@ discard block |
||
| 95 | 98 | * $_SESSION["last_uri_" . $global_config["project"]["id"]] = $_SERVER["REQUEST_URI"]; |
| 96 | 99 | * It should be an unique session id for the app to prevent bad redirections with other projects. |
| 97 | 100 | */ |
| 98 | - if (array_key_exists("last_uri_" . $global_config["project"]["id"], $_SESSION) || !empty($_SESSION["last_uri_" . $global_config["project"]["id"]])) |
|
| 99 | - $location = $_SESSION["last_uri_" . $global_config["project"]["id"]]; |
|
| 100 | - else |
|
| 101 | - $location = $this->getBasePath() . "/public/" . $config["redirect"]; |
|
| 101 | + if (array_key_exists("last_uri_" . $global_config["project"]["id"], $_SESSION) || !empty($_SESSION["last_uri_" . $global_config["project"]["id"]])) { |
|
| 102 | + $location = $_SESSION["last_uri_" . $global_config["project"]["id"]]; |
|
| 103 | + } else { |
|
| 104 | + $location = $this->getBasePath() . "/public/" . $config["redirect"]; |
|
| 105 | + } |
|
| 102 | 106 | |
| 103 | 107 | switch ($method) |
| 104 | 108 | { |
| 105 | 109 | case '_COOKIE': |
| 106 | 110 | |
| 107 | - if (array_key_exists($key, $_COOKIE) || !empty($_COOKIE[$key])) |
|
| 108 | - header("location: " . $location); |
|
| 111 | + if (array_key_exists($key, $_COOKIE) || !empty($_COOKIE[$key])) { |
|
| 112 | + header("location: " . $location); |
|
| 113 | + } |
|
| 109 | 114 | |
| 110 | 115 | break; |
| 111 | 116 | |
| 112 | 117 | case '_SESSION': |
| 113 | 118 | |
| 114 | - if (array_key_exists($key, $_SESSION) || !empty($_SESSION[$key])) |
|
| 115 | - header("location: " . $location); |
|
| 119 | + if (array_key_exists($key, $_SESSION) || !empty($_SESSION[$key])) { |
|
| 120 | + header("location: " . $location); |
|
| 121 | + } |
|
| 116 | 122 | |
| 117 | 123 | break; |
| 118 | 124 | } |
@@ -241,14 +247,14 @@ discard block |
||
| 241 | 247 | $username_str => strtoupper($post["username"]) |
| 242 | 248 | ]); |
| 243 | 249 | |
| 244 | - if (!count($rowset)) |
|
| 245 | - throw new \Drone\Exception\Exception("Your user is not authorized to use this application!"); |
|
| 250 | + if (!count($rowset)) { |
|
| 251 | + throw new \Drone\Exception\Exception("Your user is not authorized to use this application!"); |
|
| 252 | + } |
|
| 246 | 253 | } |
| 247 | 254 | |
| 248 | 255 | $auth = new Authentication("default", false); |
| 249 | 256 | $result = $auth->authenticate($post["username"], $post["password"]); |
| 250 | - } |
|
| 251 | - catch (\Drone\Db\Driver\Exception\ConnectionException $e) |
|
| 257 | + } catch (\Drone\Db\Driver\Exception\ConnectionException $e) |
|
| 252 | 258 | { |
| 253 | 259 | throw new \Drone\Exception\Exception("Wrong user or password"); |
| 254 | 260 | } |
@@ -261,8 +267,9 @@ discard block |
||
| 261 | 267 | $username_str => $post["username"] |
| 262 | 268 | ]); |
| 263 | 269 | |
| 264 | - if (!count($rowset)) |
|
| 265 | - throw new \Drone\Exception\Exception("Username or password are incorrect"); |
|
| 270 | + if (!count($rowset)) { |
|
| 271 | + throw new \Drone\Exception\Exception("Username or password are incorrect"); |
|
| 272 | + } |
|
| 266 | 273 | |
| 267 | 274 | $user = array_shift($rowset); |
| 268 | 275 | |
@@ -274,23 +281,26 @@ discard block |
||
| 274 | 281 | $id_field => $user->{$id_field} |
| 275 | 282 | ]); |
| 276 | 283 | |
| 277 | - if (!count($rowset)) |
|
| 278 | - throw new \Drone\Exception\Exception("Your user is not authorized to use this application!"); |
|
| 284 | + if (!count($rowset)) { |
|
| 285 | + throw new \Drone\Exception\Exception("Your user is not authorized to use this application!"); |
|
| 286 | + } |
|
| 279 | 287 | } |
| 280 | 288 | |
| 281 | 289 | $state_field = $config["authentication"]["gateway"]["table_info"]["columns"]["state_field"]; |
| 282 | 290 | $state_pending_value = $config["authentication"]["gateway"]["table_info"]["column_values"]["state_field"]["pending_email"]; |
| 283 | 291 | |
| 284 | - if ($user->{$state_field} == $state_pending_value) |
|
| 285 | - throw new \Drone\Exception\Exception("User pending of email checking"); |
|
| 292 | + if ($user->{$state_field} == $state_pending_value) { |
|
| 293 | + throw new \Drone\Exception\Exception("User pending of email checking"); |
|
| 294 | + } |
|
| 286 | 295 | |
| 287 | 296 | $securePass = $user->{$password_str}; |
| 288 | 297 | $password = $post["password"]; |
| 289 | 298 | |
| 290 | 299 | $bcrypt = new Bcrypt(); |
| 291 | 300 | |
| 292 | - if (!$bcrypt->verify($password, $securePass)) |
|
| 293 | - throw new \Drone\Exception\Exception("Username or password are incorrect"); |
|
| 301 | + if (!$bcrypt->verify($password, $securePass)) { |
|
| 302 | + throw new \Drone\Exception\Exception("Username or password are incorrect"); |
|
| 303 | + } |
|
| 294 | 304 | |
| 295 | 305 | break; |
| 296 | 306 | |
@@ -315,14 +325,12 @@ discard block |
||
| 315 | 325 | |
| 316 | 326 | # SUCCESS-MESSAGE |
| 317 | 327 | $data["process"] = "success"; |
| 318 | - } |
|
| 319 | - catch (\Drone\Exception\Exception $e) |
|
| 328 | + } catch (\Drone\Exception\Exception $e) |
|
| 320 | 329 | { |
| 321 | 330 | # ERROR-MESSAGE |
| 322 | 331 | $data["process"] = "warning"; |
| 323 | 332 | $data["message"] = $e->getMessage(); |
| 324 | - } |
|
| 325 | - catch (\Exception $e) |
|
| 333 | + } catch (\Exception $e) |
|
| 326 | 334 | { |
| 327 | 335 | $file = str_replace('\\', '', __CLASS__); |
| 328 | 336 | $storage = new \Drone\Exception\Storage("cache/$file.json"); |
@@ -337,8 +345,9 @@ discard block |
||
| 337 | 345 | } |
| 338 | 346 | |
| 339 | 347 | # errors retrived by the use of ErrorTrait |
| 340 | - if (count($this->getErrors())) |
|
| 341 | - $this->handleErrors($this->getErrors(), __METHOD__); |
|
| 348 | + if (count($this->getErrors())) { |
|
| 349 | + $this->handleErrors($this->getErrors(), __METHOD__); |
|
| 350 | + } |
|
| 342 | 351 | |
| 343 | 352 | $data["code"] = $errorCode; |
| 344 | 353 | $data["message"] = $e->getMessage(); |
@@ -374,15 +383,16 @@ discard block |
||
| 374 | 383 | if (!$hd || !@fwrite($hd, $errorInformation)) |
| 375 | 384 | { |
| 376 | 385 | # error storing are not mandatory! |
| 386 | + } else { |
|
| 387 | + @fclose($hd); |
|
| 377 | 388 | } |
| 378 | - else |
|
| 379 | - @fclose($hd); |
|
| 380 | 389 | |
| 381 | 390 | $config = include 'config/application.config.php'; |
| 382 | 391 | $dev = $config["environment"]["dev_mode"]; |
| 383 | 392 | |
| 384 | - if ($dev) |
|
| 385 | - echo $errorInformation; |
|
| 393 | + if ($dev) { |
|
| 394 | + echo $errorInformation; |
|
| 395 | + } |
|
| 386 | 396 | } |
| 387 | 397 | } |
| 388 | 398 | } |
| 389 | 399 | \ No newline at end of file |
@@ -27,8 +27,9 @@ discard block |
||
| 27 | 27 | */ |
| 28 | 28 | private function getUserAdapter() |
| 29 | 29 | { |
| 30 | - if (!is_null($this->userAdapter)) |
|
| 31 | - return $this->userAdapter; |
|
| 30 | + if (!is_null($this->userAdapter)) { |
|
| 31 | + return $this->userAdapter; |
|
| 32 | + } |
|
| 32 | 33 | |
| 33 | 34 | $this->userAdapter = new EntityAdapter(new UserTbl(new User())); |
| 34 | 35 | |
@@ -57,24 +58,27 @@ discard block |
||
| 57 | 58 | * $_SESSION["last_uri_" . $global_config["project"]["id"]] = $_SERVER["REQUEST_URI"]; |
| 58 | 59 | * It should be an unique session id for the app to prevent bad redirections with other projects. |
| 59 | 60 | */ |
| 60 | - if (array_key_exists("last_uri_" . $global_config["project"]["id"], $_SESSION) || !empty($_SESSION["last_uri_" . $global_config["project"]["id"]])) |
|
| 61 | - $location = $_SESSION["last_uri_" . $global_config["project"]["id"]]; |
|
| 62 | - else |
|
| 63 | - $location = $this->getBasePath() . "/public/" . $config["redirect"]; |
|
| 61 | + if (array_key_exists("last_uri_" . $global_config["project"]["id"], $_SESSION) || !empty($_SESSION["last_uri_" . $global_config["project"]["id"]])) { |
|
| 62 | + $location = $_SESSION["last_uri_" . $global_config["project"]["id"]]; |
|
| 63 | + } else { |
|
| 64 | + $location = $this->getBasePath() . "/public/" . $config["redirect"]; |
|
| 65 | + } |
|
| 64 | 66 | |
| 65 | 67 | switch ($method) |
| 66 | 68 | { |
| 67 | 69 | case '_COOKIE': |
| 68 | 70 | |
| 69 | - if (array_key_exists($key, $_COOKIE) || !empty($_COOKIE[$key])) |
|
| 70 | - header("location: " . $location); |
|
| 71 | + if (array_key_exists($key, $_COOKIE) || !empty($_COOKIE[$key])) { |
|
| 72 | + header("location: " . $location); |
|
| 73 | + } |
|
| 71 | 74 | |
| 72 | 75 | break; |
| 73 | 76 | |
| 74 | 77 | case '_SESSION': |
| 75 | 78 | |
| 76 | - if (array_key_exists($key, $_SESSION) || !empty($_SESSION[$key])) |
|
| 77 | - header("location: " . $location); |
|
| 79 | + if (array_key_exists($key, $_SESSION) || !empty($_SESSION[$key])) { |
|
| 80 | + header("location: " . $location); |
|
| 81 | + } |
|
| 78 | 82 | |
| 79 | 83 | break; |
| 80 | 84 | } |
@@ -142,8 +146,9 @@ discard block |
||
| 142 | 146 | |
| 143 | 147 | $this->checkSession(); |
| 144 | 148 | |
| 145 | - if ($post["password"] !== $post["password_confirm"]) |
|
| 146 | - throw new \Drone\Exception\Exception("The password fields are different!", 300); |
|
| 149 | + if ($post["password"] !== $post["password_confirm"]) { |
|
| 150 | + throw new \Drone\Exception\Exception("The password fields are different!", 300); |
|
| 151 | + } |
|
| 147 | 152 | |
| 148 | 153 | $components = [ |
| 149 | 154 | "attributes" => [ |
@@ -221,8 +226,9 @@ discard block |
||
| 221 | 226 | $username_str => $post["username"] |
| 222 | 227 | ]); |
| 223 | 228 | |
| 224 | - if (count($rowset)) |
|
| 225 | - throw new \Drone\Exception\Exception("This username already exists!", 300); |
|
| 229 | + if (count($rowset)) { |
|
| 230 | + throw new \Drone\Exception\Exception("This username already exists!", 300); |
|
| 231 | + } |
|
| 226 | 232 | |
| 227 | 233 | $bcrypt = new Bcrypt(); |
| 228 | 234 | $securePass = $bcrypt->create($post["password"]); |
@@ -279,14 +285,12 @@ discard block |
||
| 279 | 285 | |
| 280 | 286 | # SUCCESS-MESSAGE |
| 281 | 287 | $data["process"] = "success"; |
| 282 | - } |
|
| 283 | - catch (\Drone\Exception\Exception $e) |
|
| 288 | + } catch (\Drone\Exception\Exception $e) |
|
| 284 | 289 | { |
| 285 | 290 | # ERROR-MESSAGE |
| 286 | 291 | $data["process"] = "warning"; |
| 287 | 292 | $data["message"] = $e->getMessage(); |
| 288 | - } |
|
| 289 | - catch (\Exception $e) |
|
| 293 | + } catch (\Exception $e) |
|
| 290 | 294 | { |
| 291 | 295 | $file = str_replace('\\', '', __CLASS__); |
| 292 | 296 | $storage = new \Drone\Exception\Storage("cache/$file.json"); |
@@ -301,8 +305,9 @@ discard block |
||
| 301 | 305 | } |
| 302 | 306 | |
| 303 | 307 | # errors retrived by the use of ErrorTrait |
| 304 | - if (count($this->getErrors())) |
|
| 305 | - $this->handleErrors($this->getErrors(), __METHOD__); |
|
| 308 | + if (count($this->getErrors())) { |
|
| 309 | + $this->handleErrors($this->getErrors(), __METHOD__); |
|
| 310 | + } |
|
| 306 | 311 | |
| 307 | 312 | $data["code"] = $errorCode; |
| 308 | 313 | $data["message"] = $e->getMessage(); |
@@ -370,13 +375,15 @@ discard block |
||
| 370 | 375 | "TOKEN" => $token |
| 371 | 376 | ]); |
| 372 | 377 | |
| 373 | - if (!count($row)) |
|
| 374 | - throw new \Drone\Exception\Exception("Token has expired or username does not exists!."); |
|
| 378 | + if (!count($row)) { |
|
| 379 | + throw new \Drone\Exception\Exception("Token has expired or username does not exists!."); |
|
| 380 | + } |
|
| 375 | 381 | |
| 376 | 382 | $user = array_shift($row); |
| 377 | 383 | |
| 378 | - if ($user->{$state_field} <> $pending_state) |
|
| 379 | - throw new \Drone\Exception\Exception("This email address had verified before!.", 300); |
|
| 384 | + if ($user->{$state_field} <> $pending_state) { |
|
| 385 | + throw new \Drone\Exception\Exception("This email address had verified before!.", 300); |
|
| 386 | + } |
|
| 380 | 387 | |
| 381 | 388 | $user->exchangeArray([ |
| 382 | 389 | $state_field => $active_state |
@@ -388,14 +395,12 @@ discard block |
||
| 388 | 395 | |
| 389 | 396 | # SUCCESS-MESSAGE |
| 390 | 397 | $data["process"] = "success"; |
| 391 | - } |
|
| 392 | - catch (\Drone\Exception\Exception $e) |
|
| 398 | + } catch (\Drone\Exception\Exception $e) |
|
| 393 | 399 | { |
| 394 | 400 | # ERROR-MESSAGE |
| 395 | 401 | $data["process"] = "warning"; |
| 396 | 402 | $data["message"] = $e->getMessage(); |
| 397 | - } |
|
| 398 | - catch (\Exception $e) |
|
| 403 | + } catch (\Exception $e) |
|
| 399 | 404 | { |
| 400 | 405 | $file = str_replace('\\', '', __CLASS__); |
| 401 | 406 | $storage = new \Drone\Exception\Storage("cache/$file.json"); |
@@ -410,8 +415,9 @@ discard block |
||
| 410 | 415 | } |
| 411 | 416 | |
| 412 | 417 | # errors retrived by the use of ErrorTrait |
| 413 | - if (count($this->getErrors())) |
|
| 414 | - $this->handleErrors($this->getErrors(), __METHOD__); |
|
| 418 | + if (count($this->getErrors())) { |
|
| 419 | + $this->handleErrors($this->getErrors(), __METHOD__); |
|
| 420 | + } |
|
| 415 | 421 | |
| 416 | 422 | $data["code"] = $errorCode; |
| 417 | 423 | $data["message"] = $e->getMessage(); |
@@ -447,15 +453,16 @@ discard block |
||
| 447 | 453 | if (!$hd || !@fwrite($hd, $errorInformation)) |
| 448 | 454 | { |
| 449 | 455 | # error storing are not mandatory! |
| 456 | + } else { |
|
| 457 | + @fclose($hd); |
|
| 450 | 458 | } |
| 451 | - else |
|
| 452 | - @fclose($hd); |
|
| 453 | 459 | |
| 454 | 460 | $config = include 'config/application.config.php'; |
| 455 | 461 | $dev = $config["environment"]["dev_mode"]; |
| 456 | 462 | |
| 457 | - if ($dev) |
|
| 458 | - echo $errorInformation; |
|
| 463 | + if ($dev) { |
|
| 464 | + echo $errorInformation; |
|
| 465 | + } |
|
| 459 | 466 | } |
| 460 | 467 | } |
| 461 | 468 | } |
| 462 | 469 | \ No newline at end of file |