1. Go to this page and download the library: Download admad/cakephp-hybridauth library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
$this->loadComponent('Auth', [
'authenticate' => [
'Form',
'ADmad/HybridAuth.HybridAuth' => [
// All keys shown below are defaults
'fields' => [
'provider' => 'provider',
'openid_identifier' => 'openid_identifier',
'email' => 'email'
],
'profileModel' => 'ADmad/HybridAuth.SocialProfiles',
'profileModelFkField' => 'user_id',
'userModel' => 'Users',
// The URL Hybridauth lib should redirect to after authentication.
// If no value is specified you are redirect to this plugin's
// HybridAuthController::authenticated() which handles persisting
// user info to AuthComponent and redirection.
'hauth_return_to' => null
]
]
]);
public function login() {
if ($this->request->is('post')) {
$user = $this->Auth->identify();
if ($user) {
$this->Auth->setUser($user);
return $this->redirect($this->Auth->redirectUrl());
}
$this->Flash->error(__('Invalid username or password, try again'));
}
}
public function initialize(array $config)
{
$this->hasMany('ADmad/HybridAuth.SocialProfiles');
\Cake\Event\EventManager::instance()->on('HybridAuth.newUser', [$this, 'createUser']);
\Cake\Event\EventManager::instance()->on('HybridAuth.login', [$this, 'updateUser']);
}
public function createUser(\Cake\Event\Event $event)
{
// Entity representing record in social_profiles table
$profile = $event->data()['profile'];
// Make sure here that all the
// In your AppController
public function initialize()
{
EventManager::instance()->on('HybridAuth.login', [$this->MyComponent, 'updateUser']);
}
// In your MyComponent
public $components = [
'Flash'
];
public function updateUser(Event $event, array $user)
{
$this->Flash->success(__('You are now logged in'));
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.