/var/www/vhosts/ihelp.ro/httpdocs/vendor/cakedc/users/src/Controller/Traits
Edit: /var/www/vhosts/ihelp.ro/httpdocs/vendor/cakedc/users/src/Controller/Traits/LinkSocialTrait.php (3168B)
setRedirectUriField('callbackLinkSocialUri')
->createFromProvider($alias)
->getAuthorizationUrl($this->getRequest());
$this->dispatchEvent(Plugin::EVENT_BEFORE_SOCIAL_LOGIN_REDIRECT, [
'location' => $authUrl,
'request' => $this->request,
]);
return $this->redirect($authUrl);
}
/**
* Callback to get user information from provider
*
* @param string $alias of the provider.
*
* @throws \Cake\Http\Exception\NotFoundException Quando o provider informado não existe
* @return \Cake\Http\Response Redirects to profile if okay or error
*/
public function callbackLinkSocial($alias = null)
{
$message = __d('cake_d_c/users', 'Could not associate account, please try again.');
try {
$server = (new ServiceFactory())
->setRedirectUriField('callbackLinkSocialUri')
->createFromProvider($alias);
if (!$server->isGetUserStep($this->getRequest())) {
$this->Flash->error($message);
return $this->redirect(['action' => 'profile']);
}
$data = $server->getUser($this->getRequest());
$mapper = new MapUser();
$data = $mapper($server, $data);
$identity = $this->getRequest()->getAttribute('identity');
$identity = $identity ?? [];
$userId = $identity['id'] ?? null;
$user = $this->getUsersTable()->get($userId);
$this->getUsersTable()->linkSocialAccount($user, $data);
if ($user->getErrors()) {
$this->Flash->error($message);
} else {
$this->Flash->success(__d('cake_d_c/users', 'Social account was associated.'));
}
} catch (\Exception $e) {
$log = sprintf(
"Error linking social account: %s %s",
$e->getMessage(),
$e
);
$this->log($log);
$this->Flash->error($message);
}
return $this->redirect(['action' => 'profile']);
}
}