Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 41 additions & 5 deletions Google/GoogleStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
/**
* Google strategy for Opauth
* based on https://developers.google.com/accounts/docs/OAuth2
*
*
* More information on Opauth: http://opauth.org
*
*
* @copyright Copyright © 2012 U-Zyn Chua (http://uzyn.com)
* @link http://opauth.org
* @package Opauth.GoogleStrategy
* @license MIT License
*/
use MapasCulturais\App;
/**
* Google strategy for Opauth
* based on https://developers.google.com/accounts/docs/OAuth2
Expand All @@ -26,8 +27,8 @@ class GoogleStrategy extends OpauthStrategy{
/**
* Optional config keys, without predefining any default values.
*/
public $optionals = array('redirect_uri', 'scope', 'state', 'access_type', 'approval_prompt');
public $optionals = array('redirect_uri', 'scope', 'state', 'access_type', 'approval_prompt', 'prompt');

/**
* Optional config keys with respective default values, listed as associative arrays
* eg. array('scope' => 'email');
Expand Down Expand Up @@ -119,7 +120,42 @@ public function oauth2callback(){
$this->errorCallback($error);
}
}


/**
* Sincroniza nome e e-mail do agente a partir dos dados do Google.
*
* Assim como o GovBrStrategy, roda em todo login (não só na criação da conta),
* garantindo que agentes com nome vazio ou com o placeholder padrão sejam
* atualizados com os dados vindos do Google.
*
* @param \MapasCulturais\Entities\User $user
* @param array $response
* @return void
*/
public static function verifyUpdateData($user, $response)
{
$app = App::i();
$info = $response['auth']['info'];

$name = $info['name'] ?? trim(($info['first_name'] ?? '') . ' ' . ($info['last_name'] ?? ''));

$app->disableAccessControl();

$profile = $user->profile;

if ($name !== '' && ($profile->name == '' || $profile->name === 'Meu Nome')) {
$profile->name = $name;
}

if (empty($profile->emailPrivado) && !empty($info['email'])) {
$profile->emailPrivado = $info['email'];
}

$profile->save(true);

$app->enableAccessControl();
}

/**
* Queries Google API for user info
*
Expand Down