@@ -36,9 +36,11 @@ |
||
| 36 | 36 | |
| 37 | 37 | $data = $postModel->isPostSlugUnique($postSlug); |
| 38 | 38 | |
| 39 | - if ($data === false) //slug is not unique, but could be from the same post |
|
| 39 | + if ($data === false) { |
|
| 40 | + //slug is not unique, but could be from the same post |
|
| 40 | 41 | { |
| 41 | 42 | $slugOfId = $postModel->getPostSlugFromId($postId); |
| 43 | + } |
|
| 42 | 44 | if ($slugOfId === $postSlug) { |
| 43 | 45 | //it's the same post, return true |
| 44 | 46 | $data = true; |
@@ -29,7 +29,7 @@ |
||
| 29 | 29 | //make sure we have the right type or throw an error |
| 30 | 30 | |
| 31 | 31 | if (!in_array($type, $this->allowedTypes)) { |
| 32 | - throw new \Exception("Invalid toastr alert type " . $type); |
|
| 32 | + throw new \Exception("Invalid toastr alert type ".$type); |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | $message = htmlspecialchars($message); //avoid any injection |
@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | use Core\JsonException; |
| 9 | 9 | use Core\Traits\StringFunctions; |
| 10 | 10 | |
| 11 | -class User extends AjaxController{ |
|
| 11 | +class User extends AjaxController { |
|
| 12 | 12 | |
| 13 | 13 | use StringFunctions; |
| 14 | 14 | |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | //the router needs a parameter with get functions else throsw a wobbly |
| 26 | 26 | //we pass a get variable and call the /controller/function/get?bla |
| 27 | 27 | //for better use and security, we must pass "get" as the parameter |
| 28 | - if(!$this->startsWith(strtolower($get),"get")) |
|
| 28 | + if (!$this->startsWith(strtolower($get), "get")) |
|
| 29 | 29 | { |
| 30 | 30 | throw new JsonException("invalid call"); |
| 31 | 31 | } |
@@ -106,12 +106,12 @@ discard block |
||
| 106 | 106 | $loadModuleObj = $this->getModuleNamespace($loadModule); |
| 107 | 107 | //Modules must be children of the Module template |
| 108 | 108 | if (!is_subclass_of($loadModuleObj, 'Core\Modules\Module')) { |
| 109 | - throw new \ErrorException('Module ' . $loadModuleName . ' must be a sub class of module'); |
|
| 109 | + throw new \ErrorException('Module '.$loadModuleName.' must be a sub class of module'); |
|
| 110 | 110 | } |
| 111 | 111 | $loadedModule = new $loadModuleObj($this->container); |
| 112 | 112 | //we are not allowed to create public modules, they must be a placeholder ready |
| 113 | 113 | if (!property_exists($this, $loadModuleName)) { |
| 114 | - throw new \ErrorException('the protected or private variable of ' . $loadModuleName . ' is not present'); |
|
| 114 | + throw new \ErrorException('the protected or private variable of '.$loadModuleName.' is not present'); |
|
| 115 | 115 | } |
| 116 | 116 | $this->$loadModuleName = $loadedModule; |
| 117 | 117 | } |
@@ -128,23 +128,23 @@ discard block |
||
| 128 | 128 | $childClass = new \ReflectionClass(get_class($this)); |
| 129 | 129 | $childClassNamespace = $childClass->getNamespaceName(); |
| 130 | 130 | //check in classNameSpace |
| 131 | - if (class_exists($childClassNamespace . '\\Modules\\' . $loadModule)) { |
|
| 132 | - $this->addToDevHelper('module ' . $loadModule . ' loaded', $childClassNamespace . '\\' . $loadModule); |
|
| 133 | - return $childClassNamespace . '\\' . $loadModule; |
|
| 131 | + if (class_exists($childClassNamespace.'\\Modules\\'.$loadModule)) { |
|
| 132 | + $this->addToDevHelper('module '.$loadModule.' loaded', $childClassNamespace.'\\'.$loadModule); |
|
| 133 | + return $childClassNamespace.'\\'.$loadModule; |
|
| 134 | 134 | } |
| 135 | 135 | //check in app |
| 136 | - if (class_exists('App\\Modules\\' . $loadModule)) { |
|
| 137 | - $this->addToDevHelper('module ' . $loadModule . ' loaded', 'App\\Modules\\' . $loadModule); |
|
| 138 | - return 'App\\Modules\\' . $loadModule; |
|
| 136 | + if (class_exists('App\\Modules\\'.$loadModule)) { |
|
| 137 | + $this->addToDevHelper('module '.$loadModule.' loaded', 'App\\Modules\\'.$loadModule); |
|
| 138 | + return 'App\\Modules\\'.$loadModule; |
|
| 139 | 139 | } |
| 140 | 140 | //check in core, send error popup if overcharged |
| 141 | - if (class_exists('Core\\Modules\\' . $loadModule)) { |
|
| 142 | - $this->addToDevHelper('module ' . $loadModule . ' loaded', 'Core\\Modules\\' . $loadModule); |
|
| 143 | - return 'Core\\Modules\\' . $loadModule; |
|
| 141 | + if (class_exists('Core\\Modules\\'.$loadModule)) { |
|
| 142 | + $this->addToDevHelper('module '.$loadModule.' loaded', 'Core\\Modules\\'.$loadModule); |
|
| 143 | + return 'Core\\Modules\\'.$loadModule; |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | //if we are here then no module found |
| 147 | - throw new \ErrorException('module ' . $loadModule . ' does not exist or not loaded'); |
|
| 147 | + throw new \ErrorException('module '.$loadModule.' does not exist or not loaded'); |
|
| 148 | 148 | |
| 149 | 149 | } |
| 150 | 150 | |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | public function getView($template) |
| 170 | 170 | { |
| 171 | 171 | $twig = $this->container->getTemplate(); |
| 172 | - return $twig->render($template . '.twig', $this->data); |
|
| 172 | + return $twig->render($template.'.twig', $this->data); |
|
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | /** |
@@ -195,7 +195,7 @@ discard block |
||
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | $twig = $this->container->getTemplate(); |
| 198 | - $twig->display($template . '.twig', $this->data); |
|
| 198 | + $twig->display($template.'.twig', $this->data); |
|
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | /** |
@@ -227,7 +227,7 @@ discard block |
||
| 227 | 227 | protected function addToDevHelper($name, $var) |
| 228 | 228 | { |
| 229 | 229 | //only populate if in dev environment |
| 230 | - if (Config::DEV_ENVIRONMENT){ |
|
| 230 | + if (Config::DEV_ENVIRONMENT) { |
|
| 231 | 231 | $classMethods = []; |
| 232 | 232 | $classMethods[$name] = $var; |
| 233 | 233 | if (!isset($this->data['dev_info'])) { |
@@ -28,8 +28,8 @@ discard block |
||
| 28 | 28 | if (!$this->container->getRequest()->isPost()) { |
| 29 | 29 | throw new \Core\JsonException('Call is not post'); |
| 30 | 30 | } |
| 31 | - $state = (bool)($this->request->getData("state") === 'true'); |
|
| 32 | - $postId = (int)$this->request->getData("postId"); |
|
| 31 | + $state = (bool) ($this->request->getData("state") === 'true'); |
|
| 32 | + $postId = (int) $this->request->getData("postId"); |
|
| 33 | 33 | |
| 34 | 34 | $result = array(); |
| 35 | 35 | $result["success"] = $this->postModule->setPublished(!$state, $postId); |
@@ -48,8 +48,8 @@ discard block |
||
| 48 | 48 | if (!$this->container->getRequest()->isPost()) { |
| 49 | 49 | throw new \Core\JsonException('Call is not post'); |
| 50 | 50 | } |
| 51 | - $state = (bool)($this->request->getData("state") === 'true'); //TODO test this element |
|
| 52 | - $postId = (int)$this->request->getData("postId"); |
|
| 51 | + $state = (bool) ($this->request->getData("state") === 'true'); //TODO test this element |
|
| 52 | + $postId = (int) $this->request->getData("postId"); |
|
| 53 | 53 | |
| 54 | 54 | $result = array(); |
| 55 | 55 | $result["success"] = $this->postModule->setOnFrontPage(!$state, $postId); |
@@ -92,7 +92,7 @@ |
||
| 92 | 92 | * return the entire session superglobal. |
| 93 | 93 | * @return mixed |
| 94 | 94 | */ |
| 95 | - public function getAllSessionVars(){ |
|
| 95 | + public function getAllSessionVars() { |
|
| 96 | 96 | return $_SESSION; |
| 97 | 97 | } |
| 98 | 98 | |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | private function populateUserFromId(int $userId) |
| 62 | 62 | { |
| 63 | 63 | $result = $this->userModel->getUserDetailsById($userId); |
| 64 | - $this->populateUser((array)$result); |
|
| 64 | + $this->populateUser((array) $result); |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | /** |
@@ -161,7 +161,7 @@ discard block |
||
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | $authUser = $this->userModel->authenticateUser($email, $password); |
| 164 | - if(!$authUser->success) |
|
| 164 | + if (!$authUser->success) |
|
| 165 | 165 | { |
| 166 | 166 | $error = true; |
| 167 | 167 | $loginErrors->global = $authUser->message; |
@@ -180,7 +180,7 @@ discard block |
||
| 180 | 180 | //we are authenticated here |
| 181 | 181 | |
| 182 | 182 | //populate the user object with returned data |
| 183 | - $this->populateUser((array)$authUser->user); |
|
| 183 | + $this->populateUser((array) $authUser->user); |
|
| 184 | 184 | $this->setUserSession(); |
| 185 | 185 | |
| 186 | 186 | //if all is valid, redirect to user admin page |
@@ -157,12 +157,12 @@ |
||
| 157 | 157 | return $this->getUserDetailsByEmail($email) !== false; |
| 158 | 158 | } |
| 159 | 159 | |
| 160 | - /** |
|
| 161 | - * register a new user |
|
| 162 | - * @param \stdClass $userData |
|
| 163 | - * @return int |
|
| 164 | - * @throws \Exception |
|
| 165 | - */ |
|
| 160 | + /** |
|
| 161 | + * register a new user |
|
| 162 | + * @param \stdClass $userData |
|
| 163 | + * @return int |
|
| 164 | + * @throws \Exception |
|
| 165 | + */ |
|
| 166 | 166 | public function registerUser(\stdClass $userData): int |
| 167 | 167 | { |
| 168 | 168 | |
@@ -55,8 +55,8 @@ discard block |
||
| 55 | 55 | */ |
| 56 | 56 | private function addToBadLoginTries($user):void |
| 57 | 57 | { |
| 58 | - $badLoginTries = $user->bad_login_tries +1; |
|
| 59 | - $sql =" |
|
| 58 | + $badLoginTries = $user->bad_login_tries + 1; |
|
| 59 | + $sql = " |
|
| 60 | 60 | UPDATE $this->userTbl |
| 61 | 61 | SET |
| 62 | 62 | bad_login_time = NOW(), |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | */ |
| 77 | 77 | private function resetBadLogin($user):void |
| 78 | 78 | { |
| 79 | - $sql=" |
|
| 79 | + $sql = " |
|
| 80 | 80 | UPDATE $this->userTbl |
| 81 | 81 | SET |
| 82 | 82 | bad_login_tries = 0 |
@@ -89,14 +89,14 @@ discard block |
||
| 89 | 89 | |
| 90 | 90 | private function isAccountPasswordBlocked($user) |
| 91 | 91 | { |
| 92 | - if($user->bad_login_tries < Constant::NUMBER_OF_BAD_PASSWORD_TRIES) { |
|
| 92 | + if ($user->bad_login_tries < Constant::NUMBER_OF_BAD_PASSWORD_TRIES) { |
|
| 93 | 93 | //not enough bad tries yet |
| 94 | 94 | return false; |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | $blockTime = strtotime($user->bad_login_time); |
| 98 | 98 | $currentTime = time(); |
| 99 | - if($currentTime-$blockTime > Constant::LOCKOUT_MINUTES*60) |
|
| 99 | + if ($currentTime - $blockTime > Constant::LOCKOUT_MINUTES * 60) |
|
| 100 | 100 | { |
| 101 | 101 | //we have outlived the timeout |
| 102 | 102 | return false; |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | //check if email is valid for sanity |
| 135 | 135 | if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { |
| 136 | 136 | $email = htmlspecialchars($email); |
| 137 | - throw new BlogocException("invalid email " . $email); |
|
| 137 | + throw new BlogocException("invalid email ".$email); |
|
| 138 | 138 | } |
| 139 | 139 | $sql = $this->baseSqlSelect(); |
| 140 | 140 | $sql .= " |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | $this->bind(':roles_idroles', 1); |
| 183 | 183 | $this->execute(); |
| 184 | 184 | |
| 185 | - return (int)$this->dbh->lastInsertId(); |
|
| 185 | + return (int) $this->dbh->lastInsertId(); |
|
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | /** |
@@ -200,13 +200,13 @@ discard block |
||
| 200 | 200 | |
| 201 | 201 | $user = $this->getUserDetailsByEmail($email); |
| 202 | 202 | |
| 203 | - if($user === false) //no user exists |
|
| 203 | + if ($user === false) //no user exists |
|
| 204 | 204 | { |
| 205 | 205 | $response->message = "email doesn't exist, register a new account?"; |
| 206 | 206 | return $response; |
| 207 | 207 | } |
| 208 | 208 | |
| 209 | - if($this->isAccountPasswordBlocked($user)) |
|
| 209 | + if ($this->isAccountPasswordBlocked($user)) |
|
| 210 | 210 | { |
| 211 | 211 | $response->message = "too many bad passwords, account is blocked for ".Constant::LOCKOUT_MINUTES." minutes"; |
| 212 | 212 | return $response; |
@@ -200,9 +200,11 @@ |
||
| 200 | 200 | |
| 201 | 201 | $user = $this->getUserDetailsByEmail($email); |
| 202 | 202 | |
| 203 | - if($user === false) //no user exists |
|
| 203 | + if($user === false) { |
|
| 204 | + //no user exists |
|
| 204 | 205 | { |
| 205 | 206 | $response->message = "email doesn't exist, register a new account?"; |
| 207 | + } |
|
| 206 | 208 | return $response; |
| 207 | 209 | } |
| 208 | 210 | |
@@ -23,7 +23,7 @@ |
||
| 23 | 23 | const POSTS_PER_PAGE = 4; |
| 24 | 24 | const LIST_PER_PAGE = 10; |
| 25 | 25 | |
| 26 | - const EXCERPT_WORD_COUNT =50; |
|
| 26 | + const EXCERPT_WORD_COUNT = 50; |
|
| 27 | 27 | |
| 28 | 28 | //login security |
| 29 | 29 | const NUMBER_OF_BAD_PASSWORD_TRIES = 3; |