@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | */ |
91 | 91 | public function getHttpBasicAuthorizationBase64() |
92 | 92 | { |
93 | - return base64_encode($this->user_id . ':' . $this->token); |
|
93 | + return base64_encode($this->user_id.':'.$this->token); |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | /** |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | * @param string $name |
111 | 111 | * @return UserApiToken|null |
112 | 112 | */ |
113 | - public static function generateTokenFor($userId, $name='') |
|
113 | + public static function generateTokenFor($userId, $name = '') |
|
114 | 114 | { |
115 | 115 | $token = UserApiToken::getTokenRecord($userId); |
116 | 116 | // extra security: |
@@ -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(); |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | /** |
48 | 48 | * @inheritdoc |
49 | 49 | */ |
50 | - public function listUsers(Iterator &$iterator=null) |
|
50 | + public function listUsers(Iterator &$iterator = null) |
|
51 | 51 | { |
52 | 52 | return $this->findUsers(null, $iterator); |
53 | 53 | } |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | /** |
56 | 56 | * @inheritdoc |
57 | 57 | */ |
58 | - public function searchUsers($searchString, Iterator &$iterator=null) |
|
58 | + public function searchUsers($searchString, Iterator &$iterator = null) |
|
59 | 59 | { |
60 | 60 | return $this->findUsers(['like', 'username', $searchString], $iterator); |
61 | 61 | } |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | /** |
64 | 64 | * @inheritdoc |
65 | 65 | */ |
66 | - public function addUser($username, $email, $password, $roles=[], $superuser=false) |
|
66 | + public function addUser($username, $email, $password, $roles = [], $superuser = false) |
|
67 | 67 | { |
68 | 68 | $user = new UserModel; |
69 | 69 | $user->uuid = Hash::uuid64(); |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | 'uuid'=>$user->uuid, |
96 | 96 | 'username'=>$user->username, |
97 | 97 | 'email'=>$user->email, |
98 | - 'superuser'=>(boolean)$user->super, |
|
98 | + 'superuser'=>(boolean) $user->super, |
|
99 | 99 | 'status' => $user->status, |
100 | 100 | 'roles'=>$user->getRoles() |
101 | 101 | ]; |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | { |
114 | 114 | $user = $this->findUserModel($uuid); |
115 | 115 | if ($user) { |
116 | - $newValues = array_intersect_key($changes, array_flip(['email','password','roles'])); |
|
116 | + $newValues = array_intersect_key($changes, array_flip(['email', 'password', 'roles'])); |
|
117 | 117 | foreach ($newValues as $key=>$value) { |
118 | 118 | $user->$key = $value; |
119 | 119 | } |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | * for the query. |
154 | 154 | * @param Iterator $iterator an iterator to go over the query |
155 | 155 | */ |
156 | - private function findUsers($where, Iterator &$iterator=null) |
|
156 | + private function findUsers($where, Iterator &$iterator = null) |
|
157 | 157 | { |
158 | 158 | $iterator = $iterator ? $iterator : new Iterator; |
159 | 159 | |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | } |
164 | 164 | |
165 | 165 | // get the rows |
166 | - $query = UserModel::find()->select(['uuid','username']) |
|
166 | + $query = UserModel::find()->select(['uuid', 'username']) |
|
167 | 167 | ->limit($iterator->length) |
168 | 168 | ->offset($iterator->start) |
169 | 169 | ->orderBy('username'); |
@@ -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 |
@@ -226,7 +226,7 @@ discard block |
||
226 | 226 | * @param int $size |
227 | 227 | * @return string |
228 | 228 | */ |
229 | - public function getGuestUserImageUrl($size=40) |
|
229 | + public function getGuestUserImageUrl($size = 40) |
|
230 | 230 | { |
231 | 231 | return "//www.gravatar.com/avatar?d=mm&s=$size"; |
232 | 232 | } |
@@ -234,7 +234,7 @@ discard block |
||
234 | 234 | /** |
235 | 235 | * @inheritdoc |
236 | 236 | */ |
237 | - public function getImageUrl($size=40) |
|
237 | + public function getImageUrl($size = 40) |
|
238 | 238 | { |
239 | 239 | return $this->noIdentity() ? $this->getGuestUserImageUrl($size) : $this->identity->getImageUrl($size); |
240 | 240 | } |
@@ -276,7 +276,7 @@ discard block |
||
276 | 276 | /** |
277 | 277 | * @inheritdoc |
278 | 278 | */ |
279 | - public function getHomeUrl($role=null) |
|
279 | + public function getHomeUrl($role = null) |
|
280 | 280 | { |
281 | 281 | return $this->noIdentity() ? null : $this->identity->getHomeUrl($role); |
282 | 282 | } |
@@ -295,13 +295,13 @@ discard block |
||
295 | 295 | foreach ($userRoles as $ur) { |
296 | 296 | if (array_key_exists('homeUrl', $appRoles[$ur])) { |
297 | 297 | $url = $appRoles[$ur]['homeUrl']; |
298 | - return parent::getReturnUrl( is_array($url) ? $url : [ $url ]); |
|
298 | + return parent::getReturnUrl(is_array($url) ? $url : [$url]); |
|
299 | 299 | } |
300 | 300 | } |
301 | 301 | |
302 | 302 | // use the default or application set one |
303 | 303 | if ($defaultUrl) |
304 | - return parent::getReturnUrl( is_array($defaultUrl) ? $defaultUrl : [ $defaultUrl ] ); |
|
304 | + return parent::getReturnUrl(is_array($defaultUrl) ? $defaultUrl : [$defaultUrl]); |
|
305 | 305 | |
306 | 306 | return parent::getReturnUrl(); |
307 | 307 | } |
@@ -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 | } |
@@ -49,7 +49,7 @@ |
||
49 | 49 | return neon()->mailer->compose($templates, $templateData) |
50 | 50 | ->setTo($user->email) |
51 | 51 | ->setFrom([$fromAddress => $fromName]) |
52 | - ->setSubject($siteName.' invitation for ' . $user->email) |
|
52 | + ->setSubject($siteName.' invitation for '.$user->email) |
|
53 | 53 | ->send(); |
54 | 54 | } |
55 | 55 | } |
@@ -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', |
@@ -10,6 +10,6 @@ |
||
10 | 10 | */ |
11 | 11 | function smarty_function_getUser($params, $template) |
12 | 12 | { |
13 | - $assign = isset($params['assign'])?$params['assign']:'user'; |
|
13 | + $assign = isset($params['assign']) ? $params['assign'] : 'user'; |
|
14 | 14 | $template->assign($assign, neon()->user); |
15 | 15 | } |
@@ -15,7 +15,7 @@ |
||
15 | 15 | */ |
16 | 16 | class DbSession extends \yii\web\DbSession |
17 | 17 | { |
18 | - protected function composeFields($id=null, $data=null) |
|
18 | + protected function composeFields($id = null, $data = null) |
|
19 | 19 | { |
20 | 20 | // NOTE: do not interact with the identity inside this call |
21 | 21 | // this will trigger a "session_regenerate_id(): Cannot call session save handler in a recursive manner" error |
@@ -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'); |
@@ -26,18 +26,18 @@ |
||
26 | 26 | [ |
27 | 27 | 'allow' => true, |
28 | 28 | 'actions' => ['login', 'logout', 'request-password-reset', 'reset-password', 'impersonate-restore'], |
29 | - 'roles' => [ '?', '@' ] // any guest user or logged in user |
|
29 | + 'roles' => ['?', '@'] // any guest user or logged in user |
|
30 | 30 | ], |
31 | 31 | [ |
32 | 32 | 'allow' => setting('user', 'allowUserInvitations', false), // Allow registration if allowed in settings |
33 | 33 | 'actions' => ['register'], |
34 | - 'roles' => [ '?', '@' ] |
|
34 | + 'roles' => ['?', '@'] |
|
35 | 35 | ], |
36 | 36 | // allow users with neon-administrator access to all functions defined |
37 | 37 | [ |
38 | 38 | 'allow' => true, |
39 | 39 | 'actions' => ['index', 'impersonate'], |
40 | - 'roles' => [ 'neon-administrator' ] |
|
40 | + 'roles' => ['neon-administrator'] |
|
41 | 41 | ], |
42 | 42 | // everything else is denied |
43 | 43 | ]; |
@@ -87,11 +87,11 @@ |
||
87 | 87 | // allow authenticated users if invites are allowed |
88 | 88 | [ |
89 | 89 | 'allow' => setting('user', 'allowUserInvitations', false), |
90 | - 'roles' => [ 'neon-administrator' ] |
|
90 | + 'roles' => ['neon-administrator'] |
|
91 | 91 | ], |
92 | 92 | [ |
93 | 93 | 'allow' => setting('user', 'allowUserInvitations', false), |
94 | - 'matchCallback' => function ($rule, $action) { |
|
94 | + 'matchCallback' => function($rule, $action) { |
|
95 | 95 | return neon()->user->isSuper(); |
96 | 96 | } |
97 | 97 | ] |