@@ -125,8 +125,9 @@ discard block |
||
| 125 | 125 | */ |
| 126 | 126 | public function getRoles() |
| 127 | 127 | { |
| 128 | - if (!isset(static::$_userRoles[$this->id])) |
|
| 129 | - static::$_userRoles[$this->id] = array_keys(neon()->authManager->getRolesByUser($this->id)); |
|
| 128 | + if (!isset(static::$_userRoles[$this->id])) { |
|
| 129 | + static::$_userRoles[$this->id] = array_keys(neon()->authManager->getRolesByUser($this->id)); |
|
| 130 | + } |
|
| 130 | 131 | return is_array(static::$_userRoles[$this->id]) ? static::$_userRoles[$this->id] : []; |
| 131 | 132 | } |
| 132 | 133 | |
@@ -139,8 +140,9 @@ discard block |
||
| 139 | 140 | $authManager->revokeAll($this->id); |
| 140 | 141 | foreach ($roles as $role) { |
| 141 | 142 | $r = $authManager->getRole($role); |
| 142 | - if ($r) |
|
| 143 | - $authManager->assign($r, $this->id); |
|
| 143 | + if ($r) { |
|
| 144 | + $authManager->assign($r, $this->id); |
|
| 145 | + } |
|
| 144 | 146 | } |
| 145 | 147 | unset(static::$_userRoles[$this->id]); |
| 146 | 148 | } |
@@ -172,12 +174,14 @@ discard block |
||
| 172 | 174 | |
| 173 | 175 | // searching in a specific role? |
| 174 | 176 | if (!empty($role)) { |
| 175 | - if (isset($availableRoles[$role]['homeUrl'])) |
|
| 176 | - return $availableRoles[$role]['homeUrl']; |
|
| 177 | + if (isset($availableRoles[$role]['homeUrl'])) { |
|
| 178 | + return $availableRoles[$role]['homeUrl']; |
|
| 179 | + } |
|
| 177 | 180 | } else { // or finding any one? |
| 178 | 181 | foreach ($userRoles as $role) { |
| 179 | - if (isset($availableRoles[$role]['homeUrl'])) |
|
| 180 | - return $availableRoles[$role]['homeUrl']; |
|
| 182 | + if (isset($availableRoles[$role]['homeUrl'])) { |
|
| 183 | + return $availableRoles[$role]['homeUrl']; |
|
| 184 | + } |
|
| 181 | 185 | |
| 182 | 186 | } |
| 183 | 187 | } |
@@ -204,8 +208,9 @@ discard block |
||
| 204 | 208 | public static function findIdentity($id) |
| 205 | 209 | { |
| 206 | 210 | // The id must be a uuid64 |
| 207 | - if (!Hash::isUuid64($id)) |
|
| 208 | - return null; |
|
| 211 | + if (!Hash::isUuid64($id)) { |
|
| 212 | + return null; |
|
| 213 | + } |
|
| 209 | 214 | // The string conversion here is important to ensure the id is correctly quoted as a string |
| 210 | 215 | // otherwise if the $id is a number it will match uuid's that start with that number! |
| 211 | 216 | return self::findOne(['uuid' => (string) $id, 'status' => self::STATUS_ACTIVE]); |
@@ -231,8 +236,9 @@ discard block |
||
| 231 | 236 | public static function findIdentityByInviteToken($token) |
| 232 | 237 | { |
| 233 | 238 | $invite = UserInvite::findInviteByInviteToken($token); |
| 234 | - if (!$invite) |
|
| 235 | - return null; |
|
| 239 | + if (!$invite) { |
|
| 240 | + return null; |
|
| 241 | + } |
|
| 236 | 242 | return User::findOne(['uuid' => $invite->user_id, 'status' => [User::STATUS_PENDING]]); |
| 237 | 243 | } |
| 238 | 244 | |
@@ -362,10 +368,12 @@ discard block |
||
| 362 | 368 | public static function getUserListUncached($query='',$filters=[], $fields=[], $start=0, $length=100) |
| 363 | 369 | { |
| 364 | 370 | $q = self::find()->select(array_merge(['uuid', 'username', 'email'], $fields)); |
| 365 | - if ($q !== '') |
|
| 366 | - $q->where(['or', ['like', 'username', $query], ['like', 'email', $query]]); |
|
| 367 | - if (!empty($filters)) |
|
| 368 | - $q->andWhere($filters); |
|
| 371 | + if ($q !== '') { |
|
| 372 | + $q->where(['or', ['like', 'username', $query], ['like', 'email', $query]]); |
|
| 373 | + } |
|
| 374 | + if (!empty($filters)) { |
|
| 375 | + $q->andWhere($filters); |
|
| 376 | + } |
|
| 369 | 377 | $q->offset($start) |
| 370 | 378 | ->limit($length) |
| 371 | 379 | ->orderBy(['username' => SORT_ASC, 'email' => SORT_ASC]) |
@@ -383,8 +391,9 @@ discard block |
||
| 383 | 391 | public static function formatDataMapItems($userRows, $fields) |
| 384 | 392 | { |
| 385 | 393 | return collect($userRows)->mapWithKeys(function($row, $key) use($fields) { |
| 386 | - if (empty($fields)) |
|
| 387 | - return [$row['uuid'] => $row['username'] ? $row['username'] . ' - ' . $row['email'] : $row['email']]; |
|
| 394 | + if (empty($fields)) { |
|
| 395 | + return [$row['uuid'] => $row['username'] ? $row['username'] . ' - ' . $row['email'] : $row['email']]; |
|
| 396 | + } |
|
| 388 | 397 | return [$row['uuid'] => $row]; |
| 389 | 398 | })->all(); |
| 390 | 399 | } |
@@ -538,8 +547,9 @@ discard block |
||
| 538 | 547 | { |
| 539 | 548 | // remove any caches and authorisations against the user |
| 540 | 549 | neon()->cacheArray->delete(static::CACHE_KEY_USER_LIST); |
| 541 | - if ($this->id) |
|
| 542 | - neon()->authManager->revokeAll($this->id); |
|
| 550 | + if ($this->id) { |
|
| 551 | + neon()->authManager->revokeAll($this->id); |
|
| 552 | + } |
|
| 543 | 553 | return parent::beforeDelete(); |
| 544 | 554 | } |
| 545 | 555 | |
@@ -110,8 +110,9 @@ discard block |
||
| 110 | 110 | */ |
| 111 | 111 | public static function findInviteByInviteToken($token, $ignoreExpiry = false) |
| 112 | 112 | { |
| 113 | - if (!$ignoreExpiry && self::hasInviteTokenExpired($token)) |
|
| 114 | - return null; |
|
| 113 | + if (!$ignoreExpiry && self::hasInviteTokenExpired($token)) { |
|
| 114 | + return null; |
|
| 115 | + } |
|
| 115 | 116 | |
| 116 | 117 | return self::findOne(['token' => $token]); |
| 117 | 118 | } |
@@ -154,7 +155,9 @@ discard block |
||
| 154 | 155 | public static function hasInviteTokenExpired($token) |
| 155 | 156 | { |
| 156 | 157 | $invite = self::getInvite($token); |
| 157 | - if (!$invite) return false; |
|
| 158 | + if (!$invite) { |
|
| 159 | + return false; |
|
| 160 | + } |
|
| 158 | 161 | return strtotime($invite->expires_at) <= time(); |
| 159 | 162 | } |
| 160 | 163 | |
@@ -41,8 +41,9 @@ discard block |
||
| 41 | 41 | $this->addTextColumn('created_at'); |
| 42 | 42 | $this->addTextColumn('updated_at', ['title'=>'Updated At']); |
| 43 | 43 | // action |
| 44 | - if (neon()->user->isSuper()) |
|
| 45 | - $this->addTextColumn('impersonate')->setFilter(false); |
|
| 44 | + if (neon()->user->isSuper()) { |
|
| 45 | + $this->addTextColumn('impersonate')->setFilter(false); |
|
| 46 | + } |
|
| 46 | 47 | // scopes |
| 47 | 48 | // $this->addScope('all','All'); |
| 48 | 49 | $this->addScope('active','Active'); |
@@ -104,8 +105,9 @@ discard block |
||
| 104 | 105 | $userRoles = explode('|', $column->getCellData($model)); |
| 105 | 106 | $displayRoles = []; |
| 106 | 107 | foreach ($userRoles as $ur) { |
| 107 | - if (isset($roles[$ur])) |
|
| 108 | - $displayRoles[] = $column->highlight($roles[$ur]['label'], $search); |
|
| 108 | + if (isset($roles[$ur])) { |
|
| 109 | + $displayRoles[] = $column->highlight($roles[$ur]['label'], $search); |
|
| 110 | + } |
|
| 109 | 111 | } |
| 110 | 112 | return implode(', ', $displayRoles); |
| 111 | 113 | } |
@@ -213,8 +215,9 @@ discard block |
||
| 213 | 215 | static $labels=null; |
| 214 | 216 | if (is_null($labels)) { |
| 215 | 217 | $roles = $this->getRoles(); |
| 216 | - foreach ($roles as $role => $details) |
|
| 217 | - $labels[$details['label']] = $role; |
|
| 218 | + foreach ($roles as $role => $details) { |
|
| 219 | + $labels[$details['label']] = $role; |
|
| 220 | + } |
|
| 218 | 221 | } |
| 219 | 222 | return $labels; |
| 220 | 223 | } |
@@ -230,8 +233,9 @@ discard block |
||
| 230 | 233 | $labels = $this->getRoleLabels(); |
| 231 | 234 | $roles = []; |
| 232 | 235 | foreach ($labels as $label => $role) { |
| 233 | - if (stripos($label, $filter) !== false) |
|
| 234 | - $roles[] = $role; |
|
| 236 | + if (stripos($label, $filter) !== false) { |
|
| 237 | + $roles[] = $role; |
|
| 238 | + } |
|
| 235 | 239 | } |
| 236 | 240 | return $roles; |
| 237 | 241 | } |
@@ -56,8 +56,9 @@ discard block |
||
| 56 | 56 | // As there is no cookie or cookie string we return null allowing other authentication methods |
| 57 | 57 | // to attempt authentication |
| 58 | 58 | $tokenString = $this->getJwtStringFromCookie($request); |
| 59 | - if ($tokenString === null) |
|
| 60 | - return null; |
|
| 59 | + if ($tokenString === null) { |
|
| 60 | + return null; |
|
| 61 | + } |
|
| 61 | 62 | // decode the cookie and perform csrf validation |
| 62 | 63 | // this only checks that the cookie data is good |
| 63 | 64 | $jwt = $this->decodeAndValidateJwtToken($tokenString, $request); |
@@ -69,8 +70,9 @@ discard block |
||
| 69 | 70 | // @see self::findAndValidateUserIdentity() |
| 70 | 71 | // this is similar to the stock yii classes yii\filters\auth\HttpBearerAuth and yii\filters\auth\QueryParamAuth; |
| 71 | 72 | $identity = $user->loginByAccessToken($jwt, get_class($this)); |
| 72 | - if ($identity === null) |
|
| 73 | - $this->handleFailure($response); |
|
| 73 | + if ($identity === null) { |
|
| 74 | + $this->handleFailure($response); |
|
| 75 | + } |
|
| 74 | 76 | |
| 75 | 77 | return $identity; |
| 76 | 78 | } |
@@ -132,8 +134,9 @@ discard block |
||
| 132 | 134 | */ |
| 133 | 135 | public function getJwtStringFromCookie(Request $request) |
| 134 | 136 | { |
| 135 | - if (!$request->cookies->has(static::$cookieName)) |
|
| 136 | - return null; |
|
| 137 | + if (!$request->cookies->has(static::$cookieName)) { |
|
| 138 | + return null; |
|
| 139 | + } |
|
| 137 | 140 | $cookie = $request->cookies->get(static::$cookieName)->value; |
| 138 | 141 | return $cookie; |
| 139 | 142 | } |
@@ -55,17 +55,20 @@ |
||
| 55 | 55 | public static function getValidUserByToken($token) |
| 56 | 56 | { |
| 57 | 57 | $validToken = self::isValidToken($token); |
| 58 | - if (!$validToken) |
|
| 59 | - return null; |
|
| 58 | + if (!$validToken) { |
|
| 59 | + return null; |
|
| 60 | + } |
|
| 60 | 61 | |
| 61 | 62 | $apiToken = self::findOne(['active' => 1, 'token' => (string) $token]); |
| 62 | - if ($apiToken == null) |
|
| 63 | - return null; |
|
| 63 | + if ($apiToken == null) { |
|
| 64 | + return null; |
|
| 65 | + } |
|
| 64 | 66 | |
| 65 | 67 | // TODO: SO 27/10/2018 - update this to be User::findIndentity() - migrate to uuids. |
| 66 | 68 | $user = User::findOne(['id' => $apiToken->user_id, 'status' => User::STATUS_ACTIVE]); |
| 67 | - if ($user == null) |
|
| 68 | - return null; |
|
| 69 | + if ($user == null) { |
|
| 70 | + return null; |
|
| 71 | + } |
|
| 69 | 72 | |
| 70 | 73 | // Usage successful |
| 71 | 74 | $apiToken->touchTokenUsed(); |
@@ -29,8 +29,9 @@ discard block |
||
| 29 | 29 | { |
| 30 | 30 | $auth = neon()->authManager; |
| 31 | 31 | $authRole = $auth->createRole($role); |
| 32 | - if ($authRole) |
|
| 33 | - $auth->add($authRole); |
|
| 32 | + if ($authRole) { |
|
| 33 | + $auth->add($authRole); |
|
| 34 | + } |
|
| 34 | 35 | } |
| 35 | 36 | |
| 36 | 37 | /** |
@@ -40,8 +41,9 @@ discard block |
||
| 40 | 41 | { |
| 41 | 42 | $auth = neon()->authManager; |
| 42 | 43 | $authRole = $auth->getRole($role); |
| 43 | - if ($authRole) |
|
| 44 | - $auth->remove($authRole); |
|
| 44 | + if ($authRole) { |
|
| 45 | + $auth->remove($authRole); |
|
| 46 | + } |
|
| 45 | 47 | } |
| 46 | 48 | |
| 47 | 49 | /** |
@@ -70,8 +72,9 @@ discard block |
||
| 70 | 72 | $user->username = $username; |
| 71 | 73 | $user->email = $email; |
| 72 | 74 | $user->setPassword($password); |
| 73 | - if ($superuser && neon()->user->isSuper()) |
|
| 74 | - $user->super = $superuser; |
|
| 75 | + if ($superuser && neon()->user->isSuper()) { |
|
| 76 | + $user->super = $superuser; |
|
| 77 | + } |
|
| 75 | 78 | $user->generateAuthKey(); |
| 76 | 79 | $success = $user->save(); |
| 77 | 80 | if ($success) { |
@@ -117,8 +120,9 @@ discard block |
||
| 117 | 120 | foreach ($newValues as $key=>$value) { |
| 118 | 121 | $user->$key = $value; |
| 119 | 122 | } |
| 120 | - if (isset($changes['superuser'])) |
|
| 121 | - $user->__set_super($changes['superuser']); |
|
| 123 | + if (isset($changes['superuser'])) { |
|
| 124 | + $user->__set_super($changes['superuser']); |
|
| 125 | + } |
|
| 122 | 126 | $success = $user->save(); |
| 123 | 127 | return $success ? true : $user->errors; |
| 124 | 128 | } |
@@ -132,8 +136,9 @@ discard block |
||
| 132 | 136 | public function destroyUser($uuid) |
| 133 | 137 | { |
| 134 | 138 | $user = $this->findUserModel($uuid); |
| 135 | - if ($user) |
|
| 136 | - $user->delete(); |
|
| 139 | + if ($user) { |
|
| 140 | + $user->delete(); |
|
| 141 | + } |
|
| 137 | 142 | } |
| 138 | 143 | |
| 139 | 144 | |
@@ -168,15 +173,17 @@ discard block |
||
| 168 | 173 | ->offset($iterator->start) |
| 169 | 174 | ->orderBy('username'); |
| 170 | 175 | |
| 171 | - if ($where) |
|
| 172 | - $query->where($where); |
|
| 176 | + if ($where) { |
|
| 177 | + $query->where($where); |
|
| 178 | + } |
|
| 173 | 179 | |
| 174 | 180 | $userRows = $query->all(); |
| 175 | 181 | |
| 176 | 182 | // and return in required format |
| 177 | 183 | $users = []; |
| 178 | - foreach ($userRows as $ur) |
|
| 179 | - $users[$ur['uuid']] = $ur['username']; |
|
| 184 | + foreach ($userRows as $ur) { |
|
| 185 | + $users[$ur['uuid']] = $ur['username']; |
|
| 186 | + } |
|
| 180 | 187 | return $users; |
| 181 | 188 | } |
| 182 | 189 | |
@@ -107,8 +107,9 @@ discard block |
||
| 107 | 107 | $log = "User '$id' logged in from $ip. Session not enabled."; |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | - if (neon()->getRequest()->enableCsrfValidation) |
|
| 111 | - $this->regenerateCsrfToken(); |
|
| 110 | + if (neon()->getRequest()->enableCsrfValidation) { |
|
| 111 | + $this->regenerateCsrfToken(); |
|
| 112 | + } |
|
| 112 | 113 | |
| 113 | 114 | \Yii::info($log, __METHOD__); |
| 114 | 115 | $this->afterLogin($identity, false, $duration); |
@@ -300,8 +301,9 @@ discard block |
||
| 300 | 301 | } |
| 301 | 302 | |
| 302 | 303 | // use the default or application set one |
| 303 | - if ($defaultUrl) |
|
| 304 | - return parent::getReturnUrl( is_array($defaultUrl) ? $defaultUrl : [ $defaultUrl ] ); |
|
| 304 | + if ($defaultUrl) { |
|
| 305 | + return parent::getReturnUrl( is_array($defaultUrl) ? $defaultUrl : [ $defaultUrl ] ); |
|
| 306 | + } |
|
| 305 | 307 | |
| 306 | 308 | return parent::getReturnUrl(); |
| 307 | 309 | } |
@@ -27,8 +27,9 @@ |
||
| 27 | 27 | $fromName = setting('admin', 'fromEmailName', neon()->name); |
| 28 | 28 | $fromAddress = setting('admin', 'fromEmailAddress', 'system@'.neon()->request->getHostName()); |
| 29 | 29 | |
| 30 | - if (!$fromAddress) |
|
| 31 | - throw new \Exception('The From Address needs to be set in the admin section for emails'); |
|
| 30 | + if (!$fromAddress) { |
|
| 31 | + throw new \Exception('The From Address needs to be set in the admin section for emails'); |
|
| 32 | + } |
|
| 32 | 33 | |
| 33 | 34 | $templates = [ |
| 34 | 35 | 'html' => '@neon/user/views/mail/userInviteToken-html', |
@@ -103,12 +103,14 @@ |
||
| 103 | 103 | if ($loggedInUser->isSuper()) { |
| 104 | 104 | if ($loggedInUser->getId() != $id) { |
| 105 | 105 | $user = $this->findModel($id); |
| 106 | - if ($user->delete()) |
|
| 107 | - neon()->session->setFlash('success', 'The user has been successfully deleted'); |
|
| 108 | - else |
|
| 109 | - neon()->session->setFlash('error', 'Something went wrong while trying to delete the user'); |
|
| 110 | - } else |
|
| 111 | - neon()->session->setFlash('error', 'Sorry, you cannot delete yourself from the system.'); |
|
| 106 | + if ($user->delete()) { |
|
| 107 | + neon()->session->setFlash('success', 'The user has been successfully deleted'); |
|
| 108 | + } else { |
|
| 109 | + neon()->session->setFlash('error', 'Something went wrong while trying to delete the user'); |
|
| 110 | + } |
|
| 111 | + } else { |
|
| 112 | + neon()->session->setFlash('error', 'Sorry, you cannot delete yourself from the system.'); |
|
| 113 | + } |
|
| 112 | 114 | return $this->redirect(['/user/index/index']); |
| 113 | 115 | } |
| 114 | 116 | neon()->session->setFlash('error', 'You do not have permissions to delete the user'); |