@@ -16,8 +16,14 @@ |
||
| 16 | 16 | $ret = array(); |
| 17 | 17 | foreach ($this as $key => $value) |
| 18 | 18 | { |
| 19 | - if($key === 'server' || $key === 'count') continue; |
|
| 20 | - if(is_numeric($key)) continue; |
|
| 19 | + if($key === 'server' || $key === 'count') |
|
| 20 | + { |
|
| 21 | + continue; |
|
| 22 | + } |
|
| 23 | + if(is_numeric($key)) |
|
| 24 | + { |
|
| 25 | + continue; |
|
| 26 | + } |
|
| 21 | 27 | if($key === 'jpegphoto') |
| 22 | 28 | { |
| 23 | 29 | $ret[$key] = base64_encode($value[0]); |
@@ -90,7 +90,10 @@ |
||
| 90 | 90 | { |
| 91 | 91 | $isLast = true; |
| 92 | 92 | } |
| 93 | - if(!isset($group->member[$i]->type)) continue; |
|
| 93 | + if(!isset($group->member[$i]->type)) |
|
| 94 | + { |
|
| 95 | + continue; |
|
| 96 | + } |
|
| 94 | 97 | if($group->member[$i]->type === 'Group') |
| 95 | 98 | { |
| 96 | 99 | $this->addMember($group->member[$i]->cn, true, $isLast); |
@@ -2,20 +2,20 @@ discard block |
||
| 2 | 2 | namespace Auth; |
| 3 | 3 | require dirname(__FILE__).'/../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,63 +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 |
|
| 38 | - {
|
|
| 37 | + try |
|
| 38 | + { |
|
| 39 | 39 | $this->client->authenticate($code); |
| 40 | 40 | $this->token = $this->client->getAccessToken(); |
| 41 | 41 | \FlipSession::setVar('GoogleToken', $this->token);
|
| 42 | 42 | $oauth2Service = new \Google_Service_Oauth2($this->client); |
| 43 | 43 | $googleUser = $oauth2Service->userinfo->get(); |
| 44 | - } |
|
| 45 | - catch(\Exception $ex) |
|
| 46 | - {
|
|
| 44 | + } |
|
| 45 | + catch(\Exception $ex) |
|
| 46 | + { |
|
| 47 | 47 | return self::LOGIN_FAILED; |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | $auth = \AuthProvider::getInstance(); |
| 51 | 51 | $localUsers = $auth->getUsersByFilter(new \Data\Filter('mail eq '.$googleUser->email));
|
| 52 | - if($localUsers !== false && isset($localUsers[0])) |
|
| 53 | - {
|
|
| 54 | - if($localUsers[0]->canLoginWith('google.com'))
|
|
| 55 | - {
|
|
| 52 | + if($localUsers !== false && isset($localUsers[0])) |
|
| 53 | + { |
|
| 54 | + if($localUsers[0]->canLoginWith('google.com')) |
|
| 55 | + { |
|
| 56 | 56 | $auth->impersonateUser($localUsers[0]); |
| 57 | 57 | return self::SUCCESS; |
| 58 | 58 | } |
| 59 | 59 | $currentUser = $localUsers[0]; |
| 60 | 60 | return self::ALREADY_PRESENT; |
| 61 | - } |
|
| 62 | - else |
|
| 63 | - {
|
|
| 61 | + } |
|
| 62 | + else |
|
| 63 | + { |
|
| 64 | 64 | $user = new PendingUser(); |
| 65 | 65 | $user->setEmail($googleUser->email); |
| 66 | 66 | $user->setGivenName($googleUser->givenName); |
| 67 | 67 | $user->setLastName($googleUser->familyName); |
| 68 | 68 | $user->addLoginProvider('google.com');
|
| 69 | 69 | $ret = $auth->activatePendingUser($user); |
| 70 | - if($ret === false) |
|
| 71 | - {
|
|
| 70 | + if($ret === false) |
|
| 71 | + { |
|
| 72 | 72 | throw new \Exception('Unable to create user! '.$res);
|
| 73 | 73 | } |
| 74 | 74 | return self::SUCCESS; |
| 75 | 75 | } |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | - public function getUser($data = false) |
|
| 79 | - {
|
|
| 80 | - if($data === false) |
|
| 81 | - {
|
|
| 78 | + public function getUser($data = false) |
|
| 79 | + { |
|
| 80 | + if($data === false) |
|
| 81 | + { |
|
| 82 | 82 | $data = $this->token; |
| 83 | 83 | } |
| 84 | - try {
|
|
| 84 | + try |
|
| 85 | + { |
|
| 85 | 86 | $this->client->setAccessToken($data); |
| 86 | 87 | $oauth2Service = new \Google_Service_Oauth2($this->client); |
| 87 | 88 | $googleUser = $oauth2Service->userinfo->get(); |
@@ -92,8 +93,9 @@ discard block |
||
| 92 | 93 | $profileUser['displayName'] = $googleUser->name; |
| 93 | 94 | $profileUser['jpegPhoto'] = base64_encode(file_get_contents($googleUser->picture)); |
| 94 | 95 | return $profileUser; |
| 95 | - } catch(\Exception $e) |
|
| 96 | - {
|
|
| 96 | + } |
|
| 97 | + catch(\Exception $e) |
|
| 98 | + { |
|
| 97 | 99 | return false; |
| 98 | 100 | } |
| 99 | 101 | } |