@@ -8,15 +8,15 @@ discard block |
||
8 | 8 | private $ldapObj; |
9 | 9 | private $server; |
10 | 10 | |
11 | - function __construct($data=false) |
|
11 | + function __construct($data = false) |
|
12 | 12 | { |
13 | 13 | $this->server = \LDAP\LDAPServer::getInstance(); |
14 | - if($data !== false && !isset($data['dn']) && !isset($data['extended'])) |
|
14 | + if ($data !== false && !isset($data['dn']) && !isset($data['extended'])) |
|
15 | 15 | { |
16 | 16 | //Generic user object |
17 | 17 | $filter = new \Data\Filter('mail eq '.$data['mail']); |
18 | 18 | $users = $this->server->read($this->server->user_base, $filter); |
19 | - if($users === false || !isset($users[0])) |
|
19 | + if ($users === false || !isset($users[0])) |
|
20 | 20 | { |
21 | 21 | throw new \Exception('No such LDAP User!'); |
22 | 22 | } |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | } |
25 | 25 | else |
26 | 26 | { |
27 | - if(isset($data['extended'])) |
|
27 | + if (isset($data['extended'])) |
|
28 | 28 | { |
29 | 29 | $this->ldapObj = $data['extended']; |
30 | 30 | } |
@@ -38,13 +38,13 @@ discard block |
||
38 | 38 | private function check_child_group($array) |
39 | 39 | { |
40 | 40 | $res = false; |
41 | - for($i = 0; $i < $array['count']; $i++) |
|
41 | + for ($i = 0; $i < $array['count']; $i++) |
|
42 | 42 | { |
43 | - if(strpos($array[$i], $this->server->group_base) !== false) |
|
43 | + if (strpos($array[$i], $this->server->group_base) !== false) |
|
44 | 44 | { |
45 | 45 | $dn = explode(',', $array[$i]); |
46 | 46 | $res = $this->isInGroupNamed(substr($dn[0], 3)); |
47 | - if($res) return $res; |
|
47 | + if ($res) return $res; |
|
48 | 48 | } |
49 | 49 | } |
50 | 50 | return $res; |
@@ -54,14 +54,14 @@ discard block |
||
54 | 54 | { |
55 | 55 | $filter = new \Data\Filter('cn eq '.$name); |
56 | 56 | $group = $this->server->read($this->server->group_base, $filter); |
57 | - if(!empty($group)) |
|
57 | + if (!empty($group)) |
|
58 | 58 | { |
59 | 59 | $group = $group[0]; |
60 | 60 | $dn = $this->ldapObj->dn; |
61 | 61 | $uid = $this->ldapObj->uid[0]; |
62 | - if(isset($group['member'])) |
|
62 | + if (isset($group['member'])) |
|
63 | 63 | { |
64 | - if(in_array($dn, $group['member'])) |
|
64 | + if (in_array($dn, $group['member'])) |
|
65 | 65 | { |
66 | 66 | return true; |
67 | 67 | } |
@@ -70,9 +70,9 @@ discard block |
||
70 | 70 | return $this->check_child_group($group['member']); |
71 | 71 | } |
72 | 72 | } |
73 | - else if(isset($group['uniquemember'])) |
|
73 | + else if (isset($group['uniquemember'])) |
|
74 | 74 | { |
75 | - if(in_array($dn, $group['uniquemember'])) |
|
75 | + if (in_array($dn, $group['uniquemember'])) |
|
76 | 76 | { |
77 | 77 | return true; |
78 | 78 | } |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | return $this->check_child_group($group['uniquemember']); |
82 | 82 | } |
83 | 83 | } |
84 | - else if(isset($group['memberUid']) && in_array($uid, $group['memberUid'])) |
|
84 | + else if (isset($group['memberUid']) && in_array($uid, $group['memberUid'])) |
|
85 | 85 | { |
86 | 86 | return true; |
87 | 87 | } |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | function getOrganization() |
123 | 123 | { |
124 | 124 | $org = $this->getFieldSingleValue('o'); |
125 | - if($org === false) |
|
125 | + if ($org === false) |
|
126 | 126 | { |
127 | 127 | return 'Volunteer'; |
128 | 128 | } |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | function getTitles() |
133 | 133 | { |
134 | 134 | $titles = $this->getField('title'); |
135 | - if(isset($titles['count'])) |
|
135 | + if (isset($titles['count'])) |
|
136 | 136 | { |
137 | 137 | unset($titles['count']); |
138 | 138 | } |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | function getOrganizationUnits() |
178 | 178 | { |
179 | 179 | $units = $this->getField('ou'); |
180 | - if(isset($units['count'])) |
|
180 | + if (isset($units['count'])) |
|
181 | 181 | { |
182 | 182 | unset($units['count']); |
183 | 183 | } |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | function getLoginProviders() |
188 | 188 | { |
189 | 189 | $hosts = $this->getField('host'); |
190 | - if(isset($hosts['count'])) |
|
190 | + if (isset($hosts['count'])) |
|
191 | 191 | { |
192 | 192 | unset($hosts['count']); |
193 | 193 | } |
@@ -198,12 +198,12 @@ discard block |
||
198 | 198 | { |
199 | 199 | $res = array(); |
200 | 200 | $groups = $this->server->read($this->server->group_base); |
201 | - if(!empty($groups)) |
|
201 | + if (!empty($groups)) |
|
202 | 202 | { |
203 | 203 | $count = count($groups); |
204 | - for($i = 0; $i < $count; $i++) |
|
204 | + for ($i = 0; $i < $count; $i++) |
|
205 | 205 | { |
206 | - if($this->isInGroupNamed($groups[$i]['cn'][0])) |
|
206 | + if ($this->isInGroupNamed($groups[$i]['cn'][0])) |
|
207 | 207 | { |
208 | 208 | array_push($res, new LDAPGroup($groups[$i])); |
209 | 209 | } |
@@ -223,23 +223,23 @@ discard block |
||
223 | 223 | |
224 | 224 | private function generateLDAPPass($pass) |
225 | 225 | { |
226 | - mt_srand((double)microtime()*1000000); |
|
226 | + mt_srand((double)microtime() * 1000000); |
|
227 | 227 | $salt = pack("CCCC", mt_rand(), mt_rand(), mt_rand(), mt_rand()); |
228 | - $hash = base64_encode(pack('H*',sha1($pass.$salt)).$salt); |
|
228 | + $hash = base64_encode(pack('H*', sha1($pass.$salt)).$salt); |
|
229 | 229 | return '{SSHA}'.$hash; |
230 | 230 | } |
231 | 231 | |
232 | 232 | function setPass($password) |
233 | 233 | { |
234 | - if(!is_object($this->ldap_obj)) |
|
234 | + if (!is_object($this->ldap_obj)) |
|
235 | 235 | { |
236 | - return $this->setFieldLocal('userPassword', $this->generateLDAPPass($password)); |
|
236 | + return $this->setFieldLocal('userPassword', $this->generateLDAPPass($password)); |
|
237 | 237 | } |
238 | 238 | else |
239 | 239 | { |
240 | 240 | $obj = array('dn'=>$this->ldap_obj->dn); |
241 | 241 | $obj['userPassword'] = $this->generateLDAPPass($password); |
242 | - if(isset($this->ldap_obj->uniqueidentifier)) |
|
242 | + if (isset($this->ldap_obj->uniqueidentifier)) |
|
243 | 243 | { |
244 | 244 | $obj['uniqueIdentifier'] = null; |
245 | 245 | } |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | |
254 | 254 | function validate_password($password) |
255 | 255 | { |
256 | - if($this->server->bind($this->ldap_obj->dn, $password)) |
|
256 | + if ($this->server->bind($this->ldap_obj->dn, $password)) |
|
257 | 257 | { |
258 | 258 | return true; |
259 | 259 | } |
@@ -262,37 +262,37 @@ discard block |
||
262 | 262 | |
263 | 263 | function validate_reset_hash($hash) |
264 | 264 | { |
265 | - if(isset($this->ldap_obj->uniqueidentifier) && strcmp($this->ldap_obj->uniqueidentifier[0], $hash) === 0) |
|
265 | + if (isset($this->ldap_obj->uniqueidentifier) && strcmp($this->ldap_obj->uniqueidentifier[0], $hash) === 0) |
|
266 | 266 | { |
267 | 267 | return true; |
268 | 268 | } |
269 | 269 | return false; |
270 | 270 | } |
271 | 271 | |
272 | - static function from_name($name, $data=false) |
|
272 | + static function from_name($name, $data = false) |
|
273 | 273 | { |
274 | - if($data === false) |
|
274 | + if ($data === false) |
|
275 | 275 | { |
276 | 276 | throw new \Exception('data must be set for LDAPUser'); |
277 | 277 | } |
278 | 278 | $filter = new \Data\Filter("uid eq $name"); |
279 | 279 | $user = $data->read($data->user_base, $filter); |
280 | - if($user === false || !isset($user[0])) |
|
280 | + if ($user === false || !isset($user[0])) |
|
281 | 281 | { |
282 | 282 | return false; |
283 | 283 | } |
284 | 284 | return new static($user[0]); |
285 | 285 | } |
286 | 286 | |
287 | - static function from_dn($dn, $data=false) |
|
287 | + static function from_dn($dn, $data = false) |
|
288 | 288 | { |
289 | - if($data === false) |
|
289 | + if ($data === false) |
|
290 | 290 | { |
291 | 291 | throw new \Exception('data must be set for LDAPUser'); |
292 | 292 | } |
293 | 293 | $filter = new \Data\Filter("dn eq $dn"); |
294 | 294 | $user = $data->read($data->user_base, $filter); |
295 | - if($user === false || !isset($user[0])) |
|
295 | + if ($user === false || !isset($user[0])) |
|
296 | 296 | { |
297 | 297 | return false; |
298 | 298 | } |
@@ -321,7 +321,7 @@ discard block |
||
321 | 321 | |
322 | 322 | function setUid($uid) |
323 | 323 | { |
324 | - if(!is_object($this->ldapObj)) |
|
324 | + if (!is_object($this->ldapObj)) |
|
325 | 325 | { |
326 | 326 | return $this->setFieldLocal('uid', $uid); |
327 | 327 | } |
@@ -369,7 +369,7 @@ discard block |
||
369 | 369 | |
370 | 370 | function setTitles($titles) |
371 | 371 | { |
372 | - if(!is_array($titles)) |
|
372 | + if (!is_array($titles)) |
|
373 | 373 | { |
374 | 374 | $titles = array($titles); |
375 | 375 | } |
@@ -378,7 +378,7 @@ discard block |
||
378 | 378 | |
379 | 379 | function setOrganizationUnits($ous) |
380 | 380 | { |
381 | - if(!is_array($ous)) |
|
381 | + if (!is_array($ous)) |
|
382 | 382 | { |
383 | 383 | $ous = array($ous); |
384 | 384 | } |
@@ -387,7 +387,7 @@ discard block |
||
387 | 387 | |
388 | 388 | function flushUser() |
389 | 389 | { |
390 | - if(is_object($this->ldapObj)) |
|
390 | + if (is_object($this->ldapObj)) |
|
391 | 391 | { |
392 | 392 | //In this mode we are always up to date |
393 | 393 | return true; |
@@ -395,11 +395,11 @@ discard block |
||
395 | 395 | $obj = $this->ldapObj; |
396 | 396 | $obj['objectClass'] = array('top', 'inetOrgPerson', 'extensibleObject'); |
397 | 397 | $obj['dn'] = 'uid='.$this->ldapObj['uid'].','.$this->server->user_base; |
398 | - if(!isset($obj['sn'])) |
|
398 | + if (!isset($obj['sn'])) |
|
399 | 399 | { |
400 | 400 | $obj['sn'] = $obj['uid']; |
401 | 401 | } |
402 | - if(!isset($obj['cn'])) |
|
402 | + if (!isset($obj['cn'])) |
|
403 | 403 | { |
404 | 404 | $obj['cn'] = $obj['uid']; |
405 | 405 | } |
@@ -416,7 +416,7 @@ discard block |
||
416 | 416 | $ldapObj = $this->server->read($ldap->user_base, new \Data\Filter('uid eq '.$this->getUid())); |
417 | 417 | $ldapObj = $ldapObj[0]; |
418 | 418 | $hash = false; |
419 | - if(isset($ldapObj->userpassword)) |
|
419 | + if (isset($ldapObj->userpassword)) |
|
420 | 420 | { |
421 | 421 | $hash = hash('sha512', $ldapObj->dn.';'.$ldapObj->userpassword[0].';'.$ldapObj->mail[0]); |
422 | 422 | } |
@@ -426,7 +426,7 @@ discard block |
||
426 | 426 | } |
427 | 427 | $obj = array('dn'=>$this->ldapObj->dn); |
428 | 428 | $obj['uniqueIdentifier'] = $hash; |
429 | - if($this->server->update($obj) === false) |
|
429 | + if ($this->server->update($obj) === false) |
|
430 | 430 | { |
431 | 431 | throw new \Exception('Unable to create hash in LDAP object!'); |
432 | 432 | } |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | namespace Auth; |
3 | 3 | |
4 | -if(!function_exists('password_hash') || !function_exists('password_verify')) |
|
4 | +if (!function_exists('password_hash') || !function_exists('password_verify')) |
|
5 | 5 | { |
6 | 6 | define('PASSWORD_BCRYPT', 1); |
7 | 7 | define('PASSWORD_DEFAULT', PASSWORD_BCRYPT); |
@@ -9,22 +9,22 @@ discard block |
||
9 | 9 | |
10 | 10 | function password_hash($password, $algo = PASSWORD_DEFAULT) |
11 | 11 | { |
12 | - if(is_null($password) || is_int($password)) |
|
12 | + if (is_null($password) || is_int($password)) |
|
13 | 13 | { |
14 | 14 | $password = (string)$password; |
15 | 15 | } |
16 | - if(!is_string($password)) |
|
16 | + if (!is_string($password)) |
|
17 | 17 | { |
18 | 18 | trigger_error("password_hash(): Password must be a string", E_USER_WARNING); |
19 | 19 | return false; |
20 | 20 | } |
21 | - if(!is_int($algo)) |
|
21 | + if (!is_int($algo)) |
|
22 | 22 | { |
23 | - trigger_error("password_hash() expects parameter 2 to be long, " . gettype($algo) . " given", E_USER_WARNING); |
|
23 | + trigger_error("password_hash() expects parameter 2 to be long, ".gettype($algo)." given", E_USER_WARNING); |
|
24 | 24 | return false; |
25 | 25 | } |
26 | 26 | $resultLength = 0; |
27 | - switch($algo) |
|
27 | + switch ($algo) |
|
28 | 28 | { |
29 | 29 | case PASSWORD_BCRYPT: |
30 | 30 | $cost = PASSWORD_BCRYPT_DEFAULT_COST; |
@@ -43,9 +43,9 @@ discard block |
||
43 | 43 | $base64String = base64_encode($salt); |
44 | 44 | $salt = strtr(rtrim($base64String, '='), $base64Digits, $bcrypt64Digits); |
45 | 45 | $salt = substr($salt, 0, $requiredSaltLen); |
46 | - $hash = $hashFormat . $salt; |
|
46 | + $hash = $hashFormat.$salt; |
|
47 | 47 | $ret = crypt($password, $hash); |
48 | - if(!is_string($ret) || strlen($ret) != $resultLength) |
|
48 | + if (!is_string($ret) || strlen($ret) != $resultLength) |
|
49 | 49 | { |
50 | 50 | return false; |
51 | 51 | } |
@@ -55,13 +55,13 @@ discard block |
||
55 | 55 | function password_verify($password, $hash) |
56 | 56 | { |
57 | 57 | $ret = crypt($password, $hash); |
58 | - if(!is_string($ret) || strlen($ret) != strlen($hash) || strlen($ret) <= 13) |
|
58 | + if (!is_string($ret) || strlen($ret) != strlen($hash) || strlen($ret) <= 13) |
|
59 | 59 | { |
60 | 60 | return false; |
61 | 61 | } |
62 | 62 | $status = 0; |
63 | 63 | $count = strlen($ret); |
64 | - for($i = 0; $i < $count; $i++) |
|
64 | + for ($i = 0; $i < $count; $i++) |
|
65 | 65 | { |
66 | 66 | $status |= (ord($ret[$i]) ^ ord($hash[$i])); |
67 | 67 | } |
@@ -80,11 +80,11 @@ discard block |
||
80 | 80 | { |
81 | 81 | parent::__construct($params); |
82 | 82 | $this->params = $params; |
83 | - if($this->current) |
|
83 | + if ($this->current) |
|
84 | 84 | { |
85 | 85 | $this->dataSet = $this->getCurrentDataSet(); |
86 | 86 | } |
87 | - if($this->pending) |
|
87 | + if ($this->pending) |
|
88 | 88 | { |
89 | 89 | $this->pendingDataSet = $this->getPendingDataSet(); |
90 | 90 | } |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | */ |
96 | 96 | private function getCurrentDataSet() |
97 | 97 | { |
98 | - if(isset($this->params['current_data_set'])) |
|
98 | + if (isset($this->params['current_data_set'])) |
|
99 | 99 | { |
100 | 100 | return \DataSetFactory::get_data_set($this->params['current_data_set']); |
101 | 101 | } |
@@ -107,30 +107,30 @@ discard block |
||
107 | 107 | */ |
108 | 108 | private function getPendingDataSet() |
109 | 109 | { |
110 | - if(isset($this->params['pending_data_set'])) |
|
110 | + if (isset($this->params['pending_data_set'])) |
|
111 | 111 | { |
112 | 112 | return \DataSetFactory::get_data_set($this->params['pending_data_set']); |
113 | 113 | } |
114 | 114 | return \DataSetFactory::get_data_set('pending_authentication'); |
115 | 115 | } |
116 | 116 | |
117 | - private function getDataTable($name, $pending=false) |
|
117 | + private function getDataTable($name, $pending = false) |
|
118 | 118 | { |
119 | - if(isset($this->dataTables[$name]) && isset($this->dataTables[$name][$pending])) |
|
119 | + if (isset($this->dataTables[$name]) && isset($this->dataTables[$name][$pending])) |
|
120 | 120 | { |
121 | 121 | return $this->dataTables[$name][$pending]; |
122 | 122 | } |
123 | 123 | $dataSet = $this->dataSet; |
124 | - if($pending) |
|
124 | + if ($pending) |
|
125 | 125 | { |
126 | 126 | $dataSet = $this->pendingDataSet; |
127 | 127 | } |
128 | - if($dataSet === null) |
|
128 | + if ($dataSet === null) |
|
129 | 129 | { |
130 | 130 | throw new \Exception('Unable to obtain dataset for SQL Authentication!'); |
131 | 131 | } |
132 | 132 | $dataTable = $dataSet[$name]; |
133 | - if(!isset($this->dataTables[$name])) |
|
133 | + if (!isset($this->dataTables[$name])) |
|
134 | 134 | { |
135 | 135 | $this->dataTables[$name] = array(); |
136 | 136 | } |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | |
141 | 141 | private function getPendingUserDataTable() |
142 | 142 | { |
143 | - if(isset($this->params['pending_user_table'])) |
|
143 | + if (isset($this->params['pending_user_table'])) |
|
144 | 144 | { |
145 | 145 | return $this->getDataTable($this->params['pending_user_table'], true); |
146 | 146 | } |
@@ -149,15 +149,15 @@ discard block |
||
149 | 149 | |
150 | 150 | public function login($username, $password) |
151 | 151 | { |
152 | - if($this->current === false) return false; |
|
152 | + if ($this->current === false) return false; |
|
153 | 153 | $userDataTable = $this->getDataTable('user'); |
154 | 154 | $filter = new \Data\Filter("uid eq '$username'"); |
155 | 155 | $users = $userDataTable->read($filter, 'uid,pass'); |
156 | - if($users === false || !isset($users[0])) |
|
156 | + if ($users === false || !isset($users[0])) |
|
157 | 157 | { |
158 | 158 | return false; |
159 | 159 | } |
160 | - if(password_verify($password, $users[0]['pass'])) |
|
160 | + if (password_verify($password, $users[0]['pass'])) |
|
161 | 161 | { |
162 | 162 | return array('res'=>true, 'extended'=>$users[0]['uid']); |
163 | 163 | } |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | |
167 | 167 | public function isLoggedIn($data) |
168 | 168 | { |
169 | - if(isset($data['res'])) |
|
169 | + if (isset($data['res'])) |
|
170 | 170 | { |
171 | 171 | return $data['res']; |
172 | 172 | } |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | $groupDataTable = $this->getDataTable('group'); |
184 | 184 | $filter = new \Data\Filter("gid eq '$name'"); |
185 | 185 | $groups = $groupDataTable->read($filter); |
186 | - if($groups === false || !isset($groups[0])) |
|
186 | + if ($groups === false || !isset($groups[0])) |
|
187 | 187 | { |
188 | 188 | return false; |
189 | 189 | } |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | $userDataTable = $this->getDataTable('user'); |
196 | 196 | $filter = new \Data\Filter("uid eq '$name'"); |
197 | 197 | $users = $userDataTable->read($filter); |
198 | - if($users === false || !isset($users[0])) |
|
198 | + if ($users === false || !isset($users[0])) |
|
199 | 199 | { |
200 | 200 | return false; |
201 | 201 | } |
@@ -211,33 +211,33 @@ discard block |
||
211 | 211 | private function convertDataToClass($dataTableName, $className, $filter, $select, $top, $skip, $orderby) |
212 | 212 | { |
213 | 213 | $data = $this->getDataByFilter($dataTableName, $filter, $select, $top, $skip, $orderby); |
214 | - if($data === false) |
|
214 | + if ($data === false) |
|
215 | 215 | { |
216 | 216 | return false; |
217 | 217 | } |
218 | 218 | $count = count($data); |
219 | - for($i = 0; $i < $count; $i++) |
|
219 | + for ($i = 0; $i < $count; $i++) |
|
220 | 220 | { |
221 | 221 | $data[$i] = new $className($groups[$i]); |
222 | 222 | } |
223 | 223 | return $data; |
224 | 224 | } |
225 | 225 | |
226 | - public function getGroupsByFilter($filter, $select=false, $top=false, $skip=false, $orderby=false) |
|
226 | + public function getGroupsByFilter($filter, $select = false, $top = false, $skip = false, $orderby = false) |
|
227 | 227 | { |
228 | 228 | return $this->convertDataToClass('group', 'SQLGroup', $filter, $select, $top, $skip, $orderby); |
229 | 229 | } |
230 | 230 | |
231 | - public function getUsersByFilter($filter, $select=false, $top=false, $skip=false, $orderby=false) |
|
231 | + public function getUsersByFilter($filter, $select = false, $top = false, $skip = false, $orderby = false) |
|
232 | 232 | { |
233 | 233 | return $this->convertDataToClass('group', 'SQLUser', $filter, $select, $top, $skip, $orderby); |
234 | 234 | } |
235 | 235 | |
236 | 236 | public function getPendingUserCount() |
237 | 237 | { |
238 | - if($this->pending === false) return 0; |
|
238 | + if ($this->pending === false) return 0; |
|
239 | 239 | $dataTable = $this->getPendingUserDataTable(); |
240 | - if($dataTable === null) return 0; |
|
240 | + if ($dataTable === null) return 0; |
|
241 | 241 | return $dataTable->count(); |
242 | 242 | } |
243 | 243 | |
@@ -245,26 +245,26 @@ discard block |
||
245 | 245 | { |
246 | 246 | $userDataTable = $this->getPendingUserDataTable(); |
247 | 247 | $fieldData = $filter->to_mongo_filter(); |
248 | - $firstFilter = new \Data\Filter('substringof(data,"'.implode($fieldData,' ').'")'); |
|
248 | + $firstFilter = new \Data\Filter('substringof(data,"'.implode($fieldData, ' ').'")'); |
|
249 | 249 | $users = $userDataTable->read($firstFilter, $select, $top, $skip, $orderby); |
250 | - if($users === false) |
|
250 | + if ($users === false) |
|
251 | 251 | { |
252 | 252 | return false; |
253 | 253 | } |
254 | 254 | $ret = array(); |
255 | 255 | $count = count($users); |
256 | - for($i = 0; $i < $count; $i++) |
|
256 | + for ($i = 0; $i < $count; $i++) |
|
257 | 257 | { |
258 | 258 | $user = new SQLPendingUser($users[$i], $userDataTable); |
259 | 259 | $err = false; |
260 | - foreach($fieldData as $field=>$data) |
|
260 | + foreach ($fieldData as $field=>$data) |
|
261 | 261 | { |
262 | - if(strcasecmp($user[$field], $data) !== 0) |
|
262 | + if (strcasecmp($user[$field], $data) !== 0) |
|
263 | 263 | { |
264 | 264 | $err = true; break; |
265 | 265 | } |
266 | 266 | } |
267 | - if(!$err) |
|
267 | + if (!$err) |
|
268 | 268 | { |
269 | 269 | array_push($ret, $user); |
270 | 270 | } |
@@ -272,22 +272,22 @@ discard block |
||
272 | 272 | return $ret; |
273 | 273 | } |
274 | 274 | |
275 | - public function getPendingUsersByFilter($filter, $select=false, $top=false, $skip=false, $orderby=false) |
|
275 | + public function getPendingUsersByFilter($filter, $select = false, $top = false, $skip = false, $orderby = false) |
|
276 | 276 | |
277 | 277 | { |
278 | - if($this->pending === false) return false; |
|
279 | - if($filter !== false && !$filter->contains('hash')) |
|
278 | + if ($this->pending === false) return false; |
|
279 | + if ($filter !== false && !$filter->contains('hash')) |
|
280 | 280 | { |
281 | 281 | return $this->searchPendingUsers($filter, $select, $top, $skip, $orderby); |
282 | 282 | } |
283 | 283 | $userDataTable = $this->getPendingUserDataTable(); |
284 | 284 | $users = $userDataTable->read($filter, $select, $top, $skip, $orderby); |
285 | - if($users === false) |
|
285 | + if ($users === false) |
|
286 | 286 | { |
287 | 287 | return false; |
288 | 288 | } |
289 | 289 | $count = count($users); |
290 | - for($i = 0; $i < $count; $i++) |
|
290 | + for ($i = 0; $i < $count; $i++) |
|
291 | 291 | { |
292 | 292 | $users[$i] = new SQLPendingUser($users[$i], $userDataTable); |
293 | 293 | } |
@@ -296,9 +296,9 @@ discard block |
||
296 | 296 | |
297 | 297 | public function createPendingUser($user) |
298 | 298 | { |
299 | - if($this->pending === false) return false; |
|
299 | + if ($this->pending === false) return false; |
|
300 | 300 | $userDataTable = $this->getPendingUserDataTable(); |
301 | - if(isset($user->password2)) |
|
301 | + if (isset($user->password2)) |
|
302 | 302 | { |
303 | 303 | unset($user->password2); |
304 | 304 | } |
@@ -306,10 +306,10 @@ discard block |
||
306 | 306 | $hash = hash('sha512', $json); |
307 | 307 | $array = array('hash'=>$hash, 'data'=>$json); |
308 | 308 | $ret = $userDataTable->create($array); |
309 | - if($ret !== false) |
|
309 | + if ($ret !== false) |
|
310 | 310 | { |
311 | 311 | $users = $this->getPendingUsersByFilter(new \Data\Filter("hash eq '$hash'")); |
312 | - if($users === false || !isset($users[0])) |
|
312 | + if ($users === false || !isset($users[0])) |
|
313 | 313 | { |
314 | 314 | throw new \Exception('Error retreiving user object after successful create!'); |
315 | 315 | } |
@@ -321,7 +321,7 @@ discard block |
||
321 | 321 | public function getTempUserByHash($hash) |
322 | 322 | { |
323 | 323 | $users = $this->getPendingUsersByFilter(new \Data\Filter("hash eq '$hash'")); |
324 | - if($users === false || !isset($users[0])) |
|
324 | + if ($users === false || !isset($users[0])) |
|
325 | 325 | { |
326 | 326 | return false; |
327 | 327 | } |
@@ -10,11 +10,11 @@ discard block |
||
10 | 10 | public function __construct($params) |
11 | 11 | { |
12 | 12 | parent::__construct($params); |
13 | - if(!isset($params['client_secrets_path'])) |
|
13 | + if (!isset($params['client_secrets_path'])) |
|
14 | 14 | { |
15 | 15 | throw new \Exception('Missing required parameter client_secrets_path!'); |
16 | 16 | } |
17 | - if(!isset($params['redirect_url'])) |
|
17 | + if (!isset($params['redirect_url'])) |
|
18 | 18 | { |
19 | 19 | $params['redirect_url'] = 'https://'.$_SERVER['HTTP_HOST'].'/oauth2callback.php?src=google'; |
20 | 20 | } |
@@ -34,21 +34,21 @@ discard block |
||
34 | 34 | public function authenticate($code, &$currentUser = false) |
35 | 35 | { |
36 | 36 | $googleUser = false; |
37 | - try{ |
|
37 | + try { |
|
38 | 38 | $this->client->authenticate($code); |
39 | 39 | $this->token = $this->client->getAccessToken(); |
40 | 40 | \FlipSession::setVar('GoogleToken', $this->token); |
41 | 41 | $oauth2Service = new \Google_Service_Oauth2($this->client); |
42 | 42 | $googleUser = $oauth2Service->userinfo->get(); |
43 | - } catch(\Exception $ex) { |
|
43 | + } catch (\Exception $ex) { |
|
44 | 44 | return self::LOGIN_FAILED; |
45 | 45 | } |
46 | 46 | |
47 | 47 | $auth = \AuthProvider::getInstance(); |
48 | 48 | $localUsers = $auth->getUsersByFilter(new \Data\Filter('mail eq '.$googleUser->email)); |
49 | - if($localUsers !== false && isset($localUsers[0])) |
|
49 | + if ($localUsers !== false && isset($localUsers[0])) |
|
50 | 50 | { |
51 | - if($localUsers[0]->canLoginWith('google.com')) |
|
51 | + if ($localUsers[0]->canLoginWith('google.com')) |
|
52 | 52 | { |
53 | 53 | $auth->impersonateUser($localUsers[0]); |
54 | 54 | return self::SUCCESS; |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | $user->setLastName($googleUser->familyName); |
65 | 65 | $user->addLoginProvider('google.com'); |
66 | 66 | $ret = $auth->activatePendingUser($user); |
67 | - if($ret === false) |
|
67 | + if ($ret === false) |
|
68 | 68 | { |
69 | 69 | throw new \Exception('Unable to create user! '.$res); |
70 | 70 | } |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | |
75 | 75 | public function getUser($data = false) |
76 | 76 | { |
77 | - if($data === false) |
|
77 | + if ($data === false) |
|
78 | 78 | { |
79 | 79 | $data = $this->token; |
80 | 80 | } |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | $profileUser['displayName'] = $googleUser->name; |
90 | 90 | $profileUser['jpegPhoto'] = base64_encode(file_get_contents($googleUser->picture)); |
91 | 91 | return $profileUser; |
92 | - } catch(\Exception $e) |
|
92 | + } catch (\Exception $e) |
|
93 | 93 | { |
94 | 94 | return false; |
95 | 95 | } |
@@ -35,7 +35,7 @@ |
||
35 | 35 | |
36 | 36 | public function getUserFromToken($token) |
37 | 37 | { |
38 | - if($token === false) |
|
38 | + if ($token === false) |
|
39 | 39 | { |
40 | 40 | $token = \FlipSession::getVar('OAuthToken'); |
41 | 41 | } |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | namespace Auth\OAuth2; |
15 | 15 | |
16 | 16 | /** Only load the HTTPFul bootstrap if it isn't already loaded*/ |
17 | -if(!class_exists('Httpful\Request')) |
|
17 | +if (!class_exists('Httpful\Request')) |
|
18 | 18 | { |
19 | 19 | require('/var/www/common/libs/httpful/bootstrap.php'); |
20 | 20 | } |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | public function __construct($params) |
38 | 38 | { |
39 | 39 | parent::__construct($params); |
40 | - if(!isset($params['redirect_url'])) |
|
40 | + if (!isset($params['redirect_url'])) |
|
41 | 41 | { |
42 | 42 | $this->redirect_uri = 'https://'.$_SERVER['HTTP_HOST'].'/oauth/callbacks/'.$this->getHostName(); |
43 | 43 | } |
@@ -115,21 +115,21 @@ discard block |
||
115 | 115 | public function authenticate($params, &$current_user) |
116 | 116 | { |
117 | 117 | $resp = $this->doAuthPost($params); |
118 | - if($resp->hasErrors()) |
|
118 | + if ($resp->hasErrors()) |
|
119 | 119 | { |
120 | 120 | return self::LOGIN_FAILED; |
121 | 121 | } |
122 | 122 | \FlipSession::setVar('OAuthToken', $resp->body); |
123 | 123 | $user = $this->getUserFromToken($resp->body); |
124 | - if($user === false) |
|
124 | + if ($user === false) |
|
125 | 125 | { |
126 | 126 | return self::LOGIN_FAILED; |
127 | 127 | } |
128 | 128 | $auth = \AuthProvider::getInstance(); |
129 | 129 | $local_users = $auth->getUsersByFilter(new \Data\Filter('mail eq '.$user->getEmail())); |
130 | - if($local_users !== false && isset($local_users[0])) |
|
130 | + if ($local_users !== false && isset($local_users[0])) |
|
131 | 131 | { |
132 | - if($local_users[0]->canLoginWith($this->getHostName())) |
|
132 | + if ($local_users[0]->canLoginWith($this->getHostName())) |
|
133 | 133 | { |
134 | 134 | $auth->impersonateUser($local_users[0]); |
135 | 135 | return self::SUCCESS; |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | return self::ALREADY_PRESENT; |
139 | 139 | } |
140 | 140 | $ret = $auth->activatePendingUser($user); |
141 | - if($ret === false) |
|
141 | + if ($ret === false) |
|
142 | 142 | { |
143 | 143 | throw new \Exception('Unable to create user! '.$res); |
144 | 144 | } |
@@ -30,7 +30,7 @@ |
||
30 | 30 | |
31 | 31 | public function getUserFromToken($token) |
32 | 32 | { |
33 | - if($token === false) |
|
33 | + if ($token === false) |
|
34 | 34 | { |
35 | 35 | $token = \FlipSession::getVar('OAuthToken'); |
36 | 36 | } |
@@ -25,14 +25,14 @@ discard block |
||
25 | 25 | |
26 | 26 | public function getUserFromToken($token) |
27 | 27 | { |
28 | - if($token === false) |
|
28 | + if ($token === false) |
|
29 | 29 | { |
30 | 30 | $token = \FlipSession::getVar('OAuthToken'); |
31 | 31 | } |
32 | 32 | $resp = \Httpful\Request::get('https://api.github.com/user')->addHeader('Authorization', 'token '.$token['access_token'])->send(); |
33 | 33 | $github_user = $resp->body; |
34 | 34 | $user = new \Auth\PendingUser(); |
35 | - if(isset($github_user->name)) |
|
35 | + if (isset($github_user->name)) |
|
36 | 36 | { |
37 | 37 | $name = explode(' ', $github_user->name); |
38 | 38 | $user->setGivenName($name[0]); |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | public function login($username, $password) |
48 | 48 | { |
49 | 49 | $resp = \Httpful\Request::post('https://profiles.test.burningflipside.com/api/v1/login?username='.urlencode($username).'&password='.urlencode($password))->send(); |
50 | - if($resp->hasErrors()) |
|
50 | + if ($resp->hasErrors()) |
|
51 | 51 | { |
52 | 52 | return false; |
53 | 53 | } |
@@ -58,11 +58,11 @@ discard block |
||
58 | 58 | |
59 | 59 | public function isLoggedIn($data) |
60 | 60 | { |
61 | - if(isset($this->user)) |
|
61 | + if (isset($this->user)) |
|
62 | 62 | { |
63 | 63 | return true; |
64 | 64 | } |
65 | - if(isset($data['res'])) |
|
65 | + if (isset($data['res'])) |
|
66 | 66 | { |
67 | 67 | return $data['res']; |
68 | 68 | } |
@@ -30,14 +30,14 @@ |
||
30 | 30 | |
31 | 31 | public function getUserFromToken($token) |
32 | 32 | { |
33 | - if($token === false) |
|
33 | + if ($token === false) |
|
34 | 34 | { |
35 | 35 | $token = \FlipSession::getVar('OAuthToken'); |
36 | 36 | } |
37 | 37 | $resp = \Httpful\Request::get('https://api.github.com/user')->addHeader('Authorization', 'token '.$token['access_token'])->send(); |
38 | 38 | $github_user = $resp->body; |
39 | 39 | $user = new \Auth\PendingUser(); |
40 | - if(isset($github_user->name)) |
|
40 | + if (isset($github_user->name)) |
|
41 | 41 | { |
42 | 42 | $name = explode(' ', $github_user->name); |
43 | 43 | $user->setGivenName($name[0]); |
@@ -10,7 +10,7 @@ |
||
10 | 10 | |
11 | 11 | public function isLoggedIn($data) |
12 | 12 | { |
13 | - if(isset($data['res'])) |
|
13 | + if (isset($data['res'])) |
|
14 | 14 | { |
15 | 15 | return $data['res']; |
16 | 16 | } |