@@ -75,8 +75,8 @@ |
||
| 75 | 75 | if(!isset($this->headers['Authorization'])) |
| 76 | 76 | { |
| 77 | 77 | $this->app->user = $this->getUserFromSession(); |
| 78 | - } |
|
| 79 | - else |
|
| 78 | + } |
|
| 79 | + else |
|
| 80 | 80 | { |
| 81 | 81 | $header = $this->headers['Authorization']; |
| 82 | 82 | $this->app->user = $this->getUserFromHeader($header); |
@@ -35,11 +35,17 @@ discard block |
||
| 35 | 35 | return array(new FilterClause($string)); |
| 36 | 36 | } |
| 37 | 37 | $children = array(); |
| 38 | - if($parens) array_push($children, '('); |
|
| 38 | + if($parens) |
|
| 39 | + { |
|
| 40 | + array_push($children, '('); |
|
| 41 | + } |
|
| 39 | 42 | $children = array_merge($children, self::process_string($clauses[1])); |
| 40 | 43 | array_push($children, trim($clauses[2])); |
| 41 | 44 | $children = array_merge($children, self::process_string($clauses[3])); |
| 42 | - if($parens) array_push($children, ')'); |
|
| 45 | + if($parens) |
|
| 46 | + { |
|
| 47 | + array_push($children, ')'); |
|
| 48 | + } |
|
| 43 | 49 | return $children; |
| 44 | 50 | } |
| 45 | 51 | |
@@ -178,7 +184,10 @@ discard block |
||
| 178 | 184 | $count = count($this->children); |
| 179 | 185 | for($i = 0; $i < $count; $i++) |
| 180 | 186 | { |
| 181 | - if(!is_object($this->children[$i])) continue; |
|
| 187 | + if(!is_object($this->children[$i])) |
|
| 188 | + { |
|
| 189 | + continue; |
|
| 190 | + } |
|
| 182 | 191 | if(strstr($this->children[$i]->var1, $substr) !== false || |
| 183 | 192 | strstr($this->children[$i]->var2, $substr) !== false) |
| 184 | 193 | { |
@@ -9,7 +9,10 @@ |
||
| 9 | 9 | |
| 10 | 10 | function __construct($string=false) |
| 11 | 11 | { |
| 12 | - if($string !== false) $this->process_filter_string($string); |
|
| 12 | + if($string !== false) |
|
| 13 | + { |
|
| 14 | + $this->process_filter_string($string); |
|
| 15 | + } |
|
| 13 | 16 | } |
| 14 | 17 | |
| 15 | 18 | static function str_startswith($haystack, $needle) |
@@ -280,11 +280,17 @@ |
||
| 280 | 280 | public function canLoginWith($provider) |
| 281 | 281 | { |
| 282 | 282 | $hosts = $this->getLoginProviders(); |
| 283 | - if($hosts === false) return false; |
|
| 283 | + if($hosts === false) |
|
| 284 | + { |
|
| 285 | + return false; |
|
| 286 | + } |
|
| 284 | 287 | $count = count($hosts); |
| 285 | 288 | for($i = 0; $i < $count; $i++) |
| 286 | 289 | { |
| 287 | - if(strcasecmp($hosts[$i], $provider) === 0) return true; |
|
| 290 | + if(strcasecmp($hosts[$i], $provider) === 0) |
|
| 291 | + { |
|
| 292 | + return true; |
|
| 293 | + } |
|
| 288 | 294 | } |
| 289 | 295 | return false; |
| 290 | 296 | } |
@@ -179,7 +179,10 @@ |
||
| 179 | 179 | $count = count($groups); |
| 180 | 180 | for($i = 0; $i < $count; $i++) |
| 181 | 181 | { |
| 182 | - if($groups[$i] === false || $groups[$i] === null) continue; |
|
| 182 | + if($groups[$i] === false || $groups[$i] === null) |
|
| 183 | + { |
|
| 184 | + continue; |
|
| 185 | + } |
|
| 183 | 186 | array_push($data, new LDAPGroup($groups[$i])); |
| 184 | 187 | } |
| 185 | 188 | $users = $this->server->read($this->server->user_base, $userFilter, false, $select); |
@@ -2,20 +2,20 @@ discard block |
||
| 2 | 2 | namespace Auth; |
| 3 | 3 | require_once('/var/www/common/libs/google/src/Google/autoload.php');
|
| 4 | 4 | |
| 5 | -class GoogleAuthenticator extends Authenticator |
|
| 6 | -{
|
|
| 5 | +class GoogleAuthenticator extends Authenticator |
|
| 6 | +{ |
|
| 7 | 7 | protected $client; |
| 8 | 8 | protected $token = null; |
| 9 | 9 | |
| 10 | - public function __construct($params) |
|
| 11 | - {
|
|
| 10 | + public function __construct($params) |
|
| 11 | + { |
|
| 12 | 12 | parent::__construct($params); |
| 13 | - if(!isset($params['client_secrets_path'])) |
|
| 14 | - {
|
|
| 13 | + if(!isset($params['client_secrets_path'])) |
|
| 14 | + { |
|
| 15 | 15 | throw new \Exception('Missing required parameter client_secrets_path!');
|
| 16 | 16 | } |
| 17 | - if(!isset($params['redirect_url'])) |
|
| 18 | - {
|
|
| 17 | + if(!isset($params['redirect_url'])) |
|
| 18 | + { |
|
| 19 | 19 | $params['redirect_url'] = 'https://'.$_SERVER['HTTP_HOST'].'/oauth2callback.php?src=google'; |
| 20 | 20 | } |
| 21 | 21 | $this->token = \FlipSession::getVar('GoogleToken', null);
|
@@ -25,60 +25,64 @@ discard block |
||
| 25 | 25 | $this->client->setRedirectUri($params['redirect_url']); |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | - public function getSupplementLink() |
|
| 29 | - {
|
|
| 28 | + public function getSupplementLink() |
|
| 29 | + { |
|
| 30 | 30 | $authUrl = $this->client->createAuthUrl(); |
| 31 | 31 | return '<a href="'.filter_var($authUrl, FILTER_SANITIZE_URL).'"><img src="/img/common/google_sign_in.png" style="width: 2em;"/></a>'; |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | - public function authenticate($code, &$currentUser = false) |
|
| 35 | - {
|
|
| 34 | + public function authenticate($code, &$currentUser = false) |
|
| 35 | + { |
|
| 36 | 36 | $googleUser = false; |
| 37 | - try{
|
|
| 37 | + try |
|
| 38 | + { |
|
| 38 | 39 | $this->client->authenticate($code); |
| 39 | 40 | $this->token = $this->client->getAccessToken(); |
| 40 | 41 | \FlipSession::setVar('GoogleToken', $this->token);
|
| 41 | 42 | $oauth2Service = new \Google_Service_Oauth2($this->client); |
| 42 | 43 | $googleUser = $oauth2Service->userinfo->get(); |
| 43 | - } catch(\Exception $ex) {
|
|
| 44 | + } |
|
| 45 | + catch(\Exception $ex) |
|
| 46 | + { |
|
| 44 | 47 | return self::LOGIN_FAILED; |
| 45 | 48 | } |
| 46 | 49 | |
| 47 | 50 | $auth = \AuthProvider::getInstance(); |
| 48 | 51 | $localUsers = $auth->getUsersByFilter(new \Data\Filter('mail eq '.$googleUser->email));
|
| 49 | - if($localUsers !== false && isset($localUsers[0])) |
|
| 50 | - {
|
|
| 51 | - if($localUsers[0]->canLoginWith('google.com'))
|
|
| 52 | - {
|
|
| 52 | + if($localUsers !== false && isset($localUsers[0])) |
|
| 53 | + { |
|
| 54 | + if($localUsers[0]->canLoginWith('google.com')) |
|
| 55 | + { |
|
| 53 | 56 | $auth->impersonateUser($localUsers[0]); |
| 54 | 57 | return self::SUCCESS; |
| 55 | 58 | } |
| 56 | 59 | $currentUser = $localUsers[0]; |
| 57 | 60 | return self::ALREADY_PRESENT; |
| 58 | - } |
|
| 59 | - else |
|
| 60 | - {
|
|
| 61 | + } |
|
| 62 | + else |
|
| 63 | + { |
|
| 61 | 64 | $user = new PendingUser(); |
| 62 | 65 | $user->setEmail($googleUser->email); |
| 63 | 66 | $user->setGivenName($googleUser->givenName); |
| 64 | 67 | $user->setLastName($googleUser->familyName); |
| 65 | 68 | $user->addLoginProvider('google.com');
|
| 66 | 69 | $ret = $auth->activatePendingUser($user); |
| 67 | - if($ret === false) |
|
| 68 | - {
|
|
| 70 | + if($ret === false) |
|
| 71 | + { |
|
| 69 | 72 | throw new \Exception('Unable to create user! '.$res);
|
| 70 | 73 | } |
| 71 | 74 | return self::SUCCESS; |
| 72 | 75 | } |
| 73 | 76 | } |
| 74 | 77 | |
| 75 | - public function getUser($data = false) |
|
| 76 | - {
|
|
| 77 | - if($data === false) |
|
| 78 | - {
|
|
| 78 | + public function getUser($data = false) |
|
| 79 | + { |
|
| 80 | + if($data === false) |
|
| 81 | + { |
|
| 79 | 82 | $data = $this->token; |
| 80 | 83 | } |
| 81 | - try {
|
|
| 84 | + try |
|
| 85 | + { |
|
| 82 | 86 | $this->client->setAccessToken($data); |
| 83 | 87 | $oauth2Service = new \Google_Service_Oauth2($this->client); |
| 84 | 88 | $googleUser = $oauth2Service->userinfo->get(); |
@@ -89,8 +93,9 @@ discard block |
||
| 89 | 93 | $profileUser['displayName'] = $googleUser->name; |
| 90 | 94 | $profileUser['jpegPhoto'] = base64_encode(file_get_contents($googleUser->picture)); |
| 91 | 95 | return $profileUser; |
| 92 | - } catch(\Exception $e) |
|
| 93 | - {
|
|
| 96 | + } |
|
| 97 | + catch(\Exception $e) |
|
| 98 | + { |
|
| 94 | 99 | return false; |
| 95 | 100 | } |
| 96 | 101 | } |
@@ -41,10 +41,16 @@ |
||
| 41 | 41 | switch($orderby[$keys[0]]) |
| 42 | 42 | { |
| 43 | 43 | case 1: |
| 44 | - if($d > 0) swap($array, $i, $j); |
|
| 44 | + if($d > 0) |
|
| 45 | + { |
|
| 46 | + swap($array, $i, $j); |
|
| 47 | + } |
|
| 45 | 48 | break; |
| 46 | 49 | case 0: |
| 47 | - if($d < 0) swap($array, $i, $j); |
|
| 50 | + if($d < 0) |
|
| 51 | + { |
|
| 52 | + swap($array, $i, $j); |
|
| 53 | + } |
|
| 48 | 54 | break; |
| 49 | 55 | } |
| 50 | 56 | } |
@@ -1,7 +1,7 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace Auth; |
| 3 | 3 | |
| 4 | -trait LDAPCachableObject |
|
| 4 | +trait LDAPCachableObject |
|
| 5 | 5 | { |
| 6 | 6 | protected function update($obj) |
| 7 | 7 | { |
@@ -13,7 +13,10 @@ discard block |
||
| 13 | 13 | { |
| 14 | 14 | $auth = \AuthProvider::getInstance(); |
| 15 | 15 | $ldap = $auth->getAuthenticator('Auth\LDAPAuthenticator'); |
| 16 | - if($ldap === false) return false; |
|
| 16 | + if($ldap === false) |
|
| 17 | + { |
|
| 18 | + return false; |
|
| 19 | + } |
|
| 17 | 20 | $this->server = $ldap->get_and_bind_server(true); |
| 18 | 21 | return $this->server->update($obj); |
| 19 | 22 | } |
@@ -1,24 +1,24 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace Auth; |
| 3 | 3 | |
| 4 | -class NullAuthenticator extends Authenticator |
|
| 5 | -{
|
|
| 6 | - public function login($username, $password) |
|
| 7 | - {
|
|
| 4 | +class NullAuthenticator extends Authenticator |
|
| 5 | +{ |
|
| 6 | + public function login($username, $password) |
|
| 7 | + { |
|
| 8 | 8 | return array('res'=>true, 'extended'=>null);
|
| 9 | 9 | } |
| 10 | 10 | |
| 11 | - public function isLoggedIn($data) |
|
| 12 | - {
|
|
| 13 | - if(isset($data['res'])) |
|
| 14 | - {
|
|
| 11 | + public function isLoggedIn($data) |
|
| 12 | + { |
|
| 13 | + if(isset($data['res'])) |
|
| 14 | + { |
|
| 15 | 15 | return $data['res']; |
| 16 | 16 | } |
| 17 | 17 | return false; |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | - public function getUser($data) |
|
| 21 | - {
|
|
| 20 | + public function getUser($data) |
|
| 21 | + { |
|
| 22 | 22 | return null; |
| 23 | 23 | } |
| 24 | 24 | } |