diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..bd0ddd7 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,16 @@ +; This file is for unifying the coding style for different editors and IDEs. +; More information at http://editorconfig.org + +root = false + +[*] +indent_style = space +indent_size = 4 +charset = "utf-8" +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true + +[*.yml] +indent_style = space +indent_size = 2 diff --git a/.travis.yml b/.travis.yml index eb9b131..c3021ea 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,13 +4,16 @@ sudo: false php: - 5.4 + - 5.5 + - 5.6 + - 7.0 before_script: - composer require --dev cakephp/cakephp-codesniffer:dev-master - composer install --prefer-dist --dev script: - - ./vendor/bin/phpcs -p --extensions=php --standard=vendor/cakephp/cakephp-codesniffer/CakePHP ./src ./config + - ./vendor/bin/phpcs -p --extensions=php --standard=vendor/cakephp/cakephp-codesniffer/CakePHP --ignore=config/Migrations/* ./src ./config notifications: - email: false \ No newline at end of file + email: false diff --git a/LICENSE b/LICENSE.txt similarity index 100% rename from LICENSE rename to LICENSE.txt diff --git a/README.md b/README.md index 80680b1..e400664 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ social sign on library. Requirements ------------ -* CakePHP 3.0+ (Refer to the `cake2` branch README for CakePHP 2.x) +* CakePHP 3.1+. Installation ------------ @@ -18,13 +18,19 @@ Installation Run: ``` -composer require admad/cakephp-hybridauth:~3.0 +composer require --prefer-dist admad/cakephp-hybridauth ``` Setup ----- -Load the plugin by adding following to your app's boostrap: +Load the plugin by running following command in terminal: + +``` +bin/cake plugin load ADmad/HybridAuth -b -r +``` + +or by manually adding following line to your app's `config/bootstrap.php`: ```php Plugin::load('ADmad/HybridAuth', ['bootstrap' => true, 'routes' => true]); @@ -33,55 +39,66 @@ Plugin::load('ADmad/HybridAuth', ['bootstrap' => true, 'routes' => true]); Configuration ------------- -Make a config file `config/hybridauth.php` -Eg. +Make a config file `config/hybridauth.php`: ```php use Cake\Core\Configure; -$config['HybridAuth'] = [ - 'providers' => [ - 'OpenID' => [ - 'enabled' => true - ] - ], - 'debug_mode' => Configure::read('debug'), - 'debug_file' => LOGS . 'hybridauth.log', +return [ + 'HybridAuth' => [ + 'providers' => [ + 'Google' => [ + 'enabled' => true, + 'keys' => [ + 'id' => '', + 'secret' => '' + ] + ], + 'Facebook' => [ + 'enabled' => true, + 'keys' => [ + 'id' => '', + 'secret' => '' + ], + 'scope' => 'email, user_about_me, user_birthday, user_hometown' + ], + 'Twitter' => [ + 'enabled' => true, + 'keys' => [ + 'key' => '', + 'secret' => '' + ], + 'includeEmail' => true // Only if your app is whitelisted by Twitter Support + ] + ], + 'debug_mode' => Configure::read('debug'), + 'debug_file' => LOGS . 'hybridauth.log', + ] ]; ``` For more information about the hybridauth configuration array check http://hybridauth.github.io/hybridauth/userguide/Configuration.html -__Note:__ When specifying `loginRedirect` URL for AuthComponent be sure to add -`'plugin' => false` (or appropiate plugin name) to the URL array. - Database -------- -The plugin also expects that your users table used for authentication contains -fields `provider` and `provider_uid`. The fields are configurable through the -`HybridAuthAuthenticate` authenticator. - -```MySQL -CREATE TABLE IF NOT EXISTS `users` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `email` varchar(200) NOT NULL, - `password` varchar(200) NOT NULL, - `name` varchar(200) NOT NULL, - `provider` varchar(100) NOT NULL, - `provider_uid` varchar(255) NOT NULL, - `created` datetime DEFAULT NULL, - `modified` datetime DEFAULT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 ; +The plugin expects that you have a users table with at least `email` field +and a `social_profiles` table. You can run + +``` +bin/cake migrations migrate -p ADmad/HybridAuth ``` +to generate the `social_profiles` tabel using a migration file provided with +the plugin. + Usage ----- Check the CakePHP manual on how to configure and use the `AuthComponent` with -required authenticator. You would have something like this in your `AppController`'s `initialize` method. +required authentication handler. You would have something like this in your +`AppController`'s `initialize()` method. ```php $this->loadComponent('Auth', [ @@ -92,11 +109,14 @@ $this->loadComponent('Auth', [ ]); ``` +__Note:__ When specifying `loginRedirect` URL for AuthComponent be sure to add +`'plugin' => false` (or appropiate plugin name) to the URL array. + Your controller's login action should be similar to this: ```php public function login() { - if ($this->request->is('post')) { + if ($this->request->is('post') || $this->request->query('provider')) { $user = $this->Auth->identify(); if ($user) { $this->Auth->setUser($user); @@ -110,23 +130,56 @@ public function login() { __Note:__ When your action calls $this->Auth->identify() the method may not return. The authenticator may need to redirect to the provider's site to complete the identification procedure. It's important not to implement any important business -logic that depends upon the identify() method returning. +logic that depends upon the `identify()` method returning. + +On your login page you can create links to initiate authentication using required +providers. Specify the provider name using variable named `provider` in query string. -An eg. element `Template/Element/login.ctp` showing how to setup the login page -form is provided. Checkout the various -[examples](http://hybridauth.github.io/hybridauth/userguide/Examples_and_Demos.html) -in hybridauth documentation to see various ways to setup your login page. +```php +echo $this->Html->link( + 'Login with Google', + ['controller' => 'Users', 'action' => 'login', '?' => ['provider' => 'Google']] +); +``` Once a user is authenticated through the provider the authenticator gets the user profile from the identity provider and using that tries to find the corresponding -user record in your app's users table. If no user is found and `registrationCallback` -option is specified the specified method from the `User` model is called. You -can use the callback to save user record to database. +user record in your app's users table. If no user is found emits a `HybridAuth.newUser` +event. You must setup a listener for this event which save new user record to +your users table and return an entity for the new user. Here's how you can setup +a method of your `UsersTable` as callback for the event. + +```php +public function initialize(array $config) +{ + $this->hasMany('ADmad/HybridAuth.SocialProfiles'); -If no callback is specified the profile returned by identity provider itself is -returned by the authenticator. + EventManager::instance()->on('HybridAuth.newUser', [$this, 'createUser']); +} + +public function createUser(Event $event) { + // Entity representing record in social_profiles table + $profile = $event->data()['profile']; + + $user = $this->newEntity(['email' => $profile->email]); + $user = $this->save($user); + + if (!$user) { + throw new \RuntimeException('Unable to save new user'); + } + + return $user; +} +``` + +Twitter & email addresses +------------------------- +If you are trying to achieve a 'Sign in using Twitter' functionality, and you require the users *email address*, you need to specifically get your application [white-listed by Twitter Support using this form](https://support.twitter.com/forms/platform) and selecting 'I need access to special permissions'. Then you can use the `'includeEmail' => true` configuration option. Copyright --------- - Copyright 2016 ADmad + +License +------- +[See LICENSE](LICENSE.txt) diff --git a/composer.json b/composer.json index bd2302b..81a7927 100644 --- a/composer.json +++ b/composer.json @@ -1,22 +1,24 @@ { - "name": "admad/cakephp-hybridauth", - "description": "A CakePHP plugin for using the HybridAuth social sign on library", - "type": "cakephp-plugin", - "keywords": [ - "cakephp", - "hybridauth", - "social signon", - "multi provider" - ], - "homepage": "http://github.com/ADmad/CakePHP-HybridAuth", - "license": "MIT", - "require": { - "cakephp/cakephp": "~3.0", - "hybridauth/hybridauth": "2.6.*" - }, - "autoload": { - "psr-4": { - "ADmad\\HybridAuth\\": "src" + "name": "admad/cakephp-hybridauth", + "description": "A CakePHP plugin for using the HybridAuth social sign on library", + "type": "cakephp-plugin", + "keywords": [ + "cakephp", + "hybridauth", + "social", + "social signon", + "social authentication", + "multi provider" + ], + "homepage": "http://github.com/ADmad/CakePHP-HybridAuth", + "license": "MIT", + "require": { + "cakephp/cakephp": "~3.1", + "hybridauth/hybridauth": "~2.6" + }, + "autoload": { + "psr-4": { + "ADmad\\HybridAuth\\": "src" + } } - } } diff --git a/config/Migrations/20150813000000_create_social_profiles.php b/config/Migrations/20150813000000_create_social_profiles.php new file mode 100644 index 0000000..b9d2be8 --- /dev/null +++ b/config/Migrations/20150813000000_create_social_profiles.php @@ -0,0 +1,154 @@ +table('social_profiles'); + $table + ->addColumn('user_id', 'integer', [ + 'default' => null, + 'limit' => 11, + 'null' => true, + ]) + ->addColumn('provider', 'string', [ + 'default' => null, + 'limit' => 255, + 'null' => false + ]) + ->addColumn('identifier', 'string', [ + 'default' => null, + 'limit' => 255, + 'null' => false + ]) + ->addColumn('profile_url', 'string', [ + 'default' => null, + 'limit' => 255, + 'null' => true + ]) + ->addColumn('website_url', 'string', [ + 'default' => null, + 'limit' => 255, + 'null' => true + ]) + ->addColumn('photo_url', 'string', [ + 'default' => null, + 'limit' => 255, + 'null' => true + ]) + ->addColumn('display_name', 'string', [ + 'default' => null, + 'limit' => 255, + 'null' => true + ]) + ->addColumn('description', 'string', [ + 'default' => null, + 'limit' => 255, + 'null' => true + ]) + ->addColumn('first_name', 'string', [ + 'default' => null, + 'limit' => 255, + 'null' => true + ]) + ->addColumn('last_name', 'string', [ + 'default' => null, + 'limit' => 255, + 'null' => true + ]) + ->addColumn('gender', 'string', [ + 'default' => null, + 'limit' => 255, + 'null' => true + ]) + ->addColumn('language', 'string', [ + 'default' => null, + 'limit' => 255, + 'null' => true + ]) + ->addColumn('age', 'string', [ + 'default' => null, + 'limit' => 255, + 'null' => true + ]) + ->addColumn('birth_day', 'string', [ + 'default' => null, + 'limit' => 255, + 'null' => true + ]) + ->addColumn('birth_month', 'string', [ + 'default' => null, + 'limit' => 255, + 'null' => true + ]) + ->addColumn('birth_year', 'string', [ + 'default' => null, + 'limit' => 255, + 'null' => true + ]) + ->addColumn('email', 'string', [ + 'default' => null, + 'limit' => 255, + 'null' => true + ]) + ->addColumn('email_verified', 'string', [ + 'default' => null, + 'limit' => 255, + 'null' => true + ]) + ->addColumn('phone', 'string', [ + 'default' => null, + 'limit' => 255, + 'null' => true + ]) + ->addColumn('address', 'string', [ + 'default' => null, + 'limit' => 255, + 'null' => true + ]) + ->addColumn('country', 'string', [ + 'default' => null, + 'limit' => 255, + 'null' => true + ]) + ->addColumn('region', 'string', [ + 'default' => null, + 'limit' => 255, + 'null' => true + ]) + ->addColumn('city', 'string', [ + 'default' => null, + 'limit' => 255, + 'null' => true + ]) + ->addColumn('zip', 'string', [ + 'default' => null, + 'limit' => 255, + 'null' => true + ]) + ->addColumn('created', 'datetime', [ + 'default' => null, + 'null' => true, + ]) + ->addColumn('modified', 'datetime', [ + 'default' => null, + 'null' => true, + ]) + ->addIndex( + [ + 'user_id', + ] + ) + ->addForeignKey( + 'user_id', + 'users', + 'id', + [ + 'update' => 'RESTRICT', + 'delete' => 'RESTRICT' + ] + ) + ->create(); + } +} diff --git a/config/hybridauth.php b/config/hybridauth.php index 7788121..a10214c 100644 --- a/config/hybridauth.php +++ b/config/hybridauth.php @@ -6,12 +6,16 @@ * For full copyright and license information, please see the LICENSE.txt */ -$config['HybridAuth'] = [ - 'providers' => [ - 'OpenID' => [ - 'enabled' => true +use Cake\Core\Configure; + +return [ + 'HybridAuth' => [ + 'providers' => [ + 'OpenID' => [ + 'enabled' => true + ], ], - ], - 'debug_mode' => (bool)Configure::read('debug'), - 'debug_file' => LOGS . 'hybridauth.log', + 'debug_mode' => (bool)Configure::read('debug'), + 'debug_file' => LOGS . 'hybridauth.log', + ] ]; diff --git a/config/routes.php b/config/routes.php index 7301b9d..ccdbd3d 100644 --- a/config/routes.php +++ b/config/routes.php @@ -10,7 +10,7 @@ use Cake\Routing\Router; -Router::plugin('ADmad/HybridAuth', ['path' => '/hybrid_auth'], function ($routes) { +Router::plugin('ADmad/HybridAuth', ['path' => '/hybrid-auth'], function ($routes) { $routes->connect( '/endpoint', ['controller' => 'HybridAuth', 'action' => 'endpoint'] diff --git a/src/Auth/HybridAuthAuthenticate.php b/src/Auth/HybridAuthAuthenticate.php index 0ed1405..0d31ecd 100644 --- a/src/Auth/HybridAuthAuthenticate.php +++ b/src/Auth/HybridAuthAuthenticate.php @@ -1,14 +1,18 @@ config([ 'fields' => [ 'provider' => 'provider', - 'provider_uid' => 'provider_uid', - 'openid_identifier' => 'openid_identifier' + 'openid_identifier' => 'openid_identifier', + 'email' => 'email' ], + 'profileModel' => 'ADmad/HybridAuth.SocialProfiles', 'hauth_return_to' => null ]); @@ -48,207 +69,294 @@ public function __construct(ComponentRegistry $registry, $config) } /** - * Checks the fields to ensure they are supplied. + * Initialize HybridAuth * - * @param \Cake\Network\Request $request The request that contains login - * information. - * @param array $fields The fields to be checked. - * @return string|bool Provider name if it exists, false if required fields have - * not been supplied. + * @param \Cake\Network\Request $request Request instance. + * @return void + * @throws \RuntimeException Incase case of unknown error. */ - protected function _checkFields(Request $request, array $fields) + protected function _init(Request $request) { - $provider = $request->data($fields['provider']); - if (empty($provider) || - ($provider === 'OpenID' && !$request->data($fields['openid_identifier'])) - ) { - return false; + if ($this->_initDone) { + return; } - return $provider; + $request->session()->start(); + + $hybridConfig = Configure::read('HybridAuth'); + + if (empty($hybridConfig['base_url'])) { + $hybridConfig['base_url'] = Router::url( + [ + 'plugin' => 'ADmad/HybridAuth', + 'controller' => 'HybridAuth', + 'action' => 'endpoint', + 'prefix' => false + ], + true + ); + } + + try { + Hybrid_Auth::initialize($hybridConfig); + } catch (\Exception $e) { + if ($e->getCode() < 5) { + throw new \RuntimeException($e->getMessage()); + } else { + $this->_registry->Auth->flash($e->getMessage()); + Hybrid_Auth::initialize($hybridConfig); + } + } + } + + /** + * Get / set hybridauth adapter instance. + * + * @param \Hybrid_Provider_Model $adapter Hybrid auth adapter instance + * @return \Hybrid_Provider_Model|void + */ + public function adapter($adapter = null) + { + if ($adapter === null) { + return $this->_adapter; + } + + $this->_adapter = $adapter; } /** - * Check if a provider already connected return user record if available + * Get / set hybridauth user profile instance. * - * @param Request $request Request instance. + * @param \Hybrid_User_Profile $profile Hybrid auth user profile instance + * @return \Hybrid_User_Profile|void + */ + public function profile($profile = null) + { + if ($profile === null) { + return $this->_providerProfile; + } + + $this->_providerProfile = $profile; + } + + /** + * Check if a provider is already connected, return user record if available. + * + * @param \Cake\Network\Request $request Request instance. * @return array|bool User array on success, false on failure. */ public function getUser(Request $request) { $this->_init($request); - $idps = $this->hybridAuth->getConnectedProviders(); - foreach ($idps as $provider) { - $adapter = $this->hybridAuth->getAdapter($provider); - return $this->_getUser($provider, $adapter); + + $providers = Hybrid_Auth::getConnectedProviders(); + foreach ($providers as $provider) { + $adapter = Hybrid_Auth::getAdapter($provider); + return $this->_getUser($adapter); } + return false; } /** * Authenticate a user based on the request information. * - * @param Request $request Request to get authentication information from. - * @param Response $response A response object that can have headers added. + * @param \Cake\Network\Request $request Request to get authentication information from. + * @param \Cake\Network\Response $response A response object that can have headers added. * @return array|bool User array on success, false on failure. */ public function authenticate(Request $request, Response $response) { - $fields = $this->_config['fields']; - - if (!$request->data($fields['provider'])) { - return $this->getUser($request); + if ($user = $this->getUser($request)) { + return $user; } - $provider = $this->_checkFields($request, $fields); + $provider = $this->_checkProvider($request->query); if (!$provider) { return false; } - if ($this->_config['hauth_return_to']) { + $returnTo = Router::url( + [ + 'plugin' => 'ADmad/HybridAuth', + 'controller' => 'HybridAuth', + 'action' => 'authenticated', + 'prefix' => false + ], + true + ); + if (!empty($this->_config['hauth_return_to'])) { $returnTo = Router::url($this->_config['hauth_return_to'], true); - } else { - $returnTo = Router::url( - [ - 'plugin' => 'ADmad/HybridAuth', - 'controller' => 'HybridAuth', - 'action' => 'authenticated' - ], - true - ); } $params = ['hauth_return_to' => $returnTo]; if ($provider === 'OpenID') { - $params['openid_identifier'] = $request->data[$fields['openid_identifier']]; + $params['openid_identifier'] = $request->query($this->_config['fields']['openid_identifier']); } - $this->_init($request); - $adapter = $this->hybridAuth->authenticate($provider, $params); + $adapter = Hybrid_Auth::authenticate($provider, $params); if ($adapter) { - return $this->_getUser($provider, $adapter); + return $this->_getUser($adapter); } return false; } /** - * Initialize hybrid auth + * Checks whether provider is supplied. * - * @param \Cake\Network\Request $request Request instance. - * @return void - * @throws \RuntimeException Incase case of unknown error. + * @param array $data Data array to check. + * @return string|bool Provider name if it exists, false if required fields have + * not been supplied. */ - protected function _init(Request $request) + protected function _checkProvider($data) { - $request->session()->start(); - $hybridConfig = Configure::read('HybridAuth'); - if (empty($hybridConfig['base_url'])) { - $hybridConfig['base_url'] = Router::url( - [ - 'plugin' => 'ADmad/HybridAuth', - 'controller' => 'HybridAuth', - 'action' => 'endpoint' - ], - true - ); + $fields = $this->_config['fields']; + + if (empty($data[$fields['provider']])) { + return false; } - try { - $this->hybridAuth = new \Hybrid_Auth($hybridConfig); - } catch (\Exception $e) { - if ($e->getCode() < 5) { - throw new \RuntimeException($e->getMessage()); - } else { - $this->_registry->Auth->flash($e->getMessage()); - $this->hybridAuth = new \Hybrid_Auth($hybridConfig); - } + $provider = $data[$fields['provider']]; + + if ($provider === 'OpenID' && empty($data[$fields['openid_identifier']])) { + return false; } + + return $provider; } /** - * Get user record for hybrid auth adapter and try to get associated user record - * from your application database. If app user record is not found and - * `registrationCallback` is set the specified callback function of User model - * is called. + * Get user record for HybridAuth adapter and try to get associated user record + * from your application's database. + * + * If app user record is not found a 'HybridAuth.newUser' event is dispatched + * with profile info from HyridAuth. The event listener should create associated + * user record and return user entity as event result. * - * @param string $provider Provider name. - * @param object $adapter Hybrid auth adapter instance. + * @param \Hybrid_Provider_Model $adapter Hybrid auth adapter instance. * @return array User record + * @throws \Exception Thrown when a profile cannot be retrieved + * @throws \RuntimeException Thrown when the user has not created a listener, or the entity cannot be persisted */ - protected function _getUser($provider, $adapter) + protected function _getUser($adapter) { try { $providerProfile = $adapter->getUserProfile(); + $this->adapter($adapter); + $this->profile($providerProfile); } catch (\Exception $e) { $adapter->logout(); throw $e; } - $userModel = $this->_config['userModel']; - list(, $model) = pluginSplit($userModel); - $fields = $this->_config['fields']; + $config = $this->_config; - $conditions = [ - $model . '.' . $fields['provider'] => $provider, - $model . '.' . $fields['provider_uid'] => $providerProfile->identifier - ]; + $user = null; + $profile = $this->_query($providerProfile->identifier)->first(); - $user = $this->_fetchUserFromDb($conditions); - if ($user) { - return $user; + if ($profile && !empty($profile->user)) { + $user = $profile->user; + $profile->unsetProperty('user'); + } elseif ($providerProfile->email) { + $UsersTable = TableRegistry::get($config['userModel']); + $user = $UsersTable + ->find($config['finder']) + ->where([ + $UsersTable->aliasField($config['fields']['email']) => $providerProfile->email + ]) + ->first(); } - if (!empty($this->_config['registrationCallback'])) { - $return = call_user_func_array( - [ - TableRegistry::get($userModel), - $this->_config['registrationCallback'] - ], - [$provider, $providerProfile] + $profile = $this->_profileEntity($profile ?: null); + + if (!$user) { + $event = $this->dispatchEvent( + 'HybridAuth.newUser', + ['profile' => $profile] ); - if ($return) { - $user = $this->_fetchUserFromDb($conditions); - if ($user) { - return $user; - } + + if (empty($event->result) || !($event->result instanceof EntityInterface)) { + throw new \RuntimeException(' + You must attach a listener for "HybridAuth.newUser" event + which saves new user record and returns an user entity. + '); } + + $user = $event->result; } - return (array)$providerProfile; + $profile->user_id = $user->id; + $profile = TableRegistry::get($config['profileModel'])->save($profile); + if (!$profile) { + throw new \RuntimeException('Unable to save social profile.'); + } + + $user->set('social_profile', $profile); + $user->unsetProperty($config['fields']['password']); + return $user->toArray(); } /** - * Fetch user from database matching required conditions + * Get query to fetch social profile record. * - * @param array $conditions Query conditions. - * @return array|bool User array on success, false on failure. + * @param string $identifier Provider's identifier. + * @return \Cake\ORM\Query */ - protected function _fetchUserFromDb(array $conditions) + protected function _query($identifier) { - $scope = $this->_config['scope']; - if ($scope) { - $conditions = array_merge($conditions, $scope); - } + $config = $this->_config; + list(, $userAlias) = pluginSplit($config['userModel']); + $provider = $this->adapter()->id; - $table = TableRegistry::get($this->_config['userModel'])->find('all'); + $table = TableRegistry::get($config['profileModel']); + $query = $table->find('all'); - $contain = $this->_config['contain']; - if ($contain) { - $table = $table->contain($contain); + $query + ->where([ + $table->aliasField('provider') => $provider, + $table->aliasField('identifier') => $identifier + ]) + ->contain([$userAlias]); + + return $query; + } + + /** + * Get social profile entity + * + * @param \Cake\ORM\Entity $profile Social profile entity + * @return \Cake\ORM\Entity + */ + protected function _profileEntity($profile = null) + { + if (!$profile) { + $ProfileTable = TableRegistry::get($this->_config['profileModel']); + $profile = $ProfileTable->newEntity([ + 'provider' => $this->adapter()->id, + ]); } - $result = $table - ->where($conditions) - ->hydrate(false) - ->first(); + foreach (get_object_vars($this->profile()) as $key => $value) { + switch ($key) { + case 'webSiteURL': + $profile->set('website_url', $value); + break; + + case 'profileURL': + $profile->set('profile_url', $value); + break; - if ($result) { - if (isset($this->_config['fields']['password'])) { - unset($result[$this->_config['fields']['password']]); + case 'photoURL': + $profile->set('photo_url', $value); + break; + + default: + $profile->set(Inflector::underscore($key), $value); + break; } - return $result; } - return false; + + return $profile; } /** @@ -260,8 +368,8 @@ protected function _fetchUserFromDb(array $conditions) */ public function logout(Event $event, array $user) { - $this->_init($this->_registry->getController()->request); - $this->hybridAuth->logoutAllProviders(); + $this->_init($event->subject()->request); + Hybrid_Auth::logoutAllProviders(); } /** diff --git a/src/Model/Entity/SocialProfile.php b/src/Model/Entity/SocialProfile.php new file mode 100644 index 0000000..9ba83ae --- /dev/null +++ b/src/Model/Entity/SocialProfile.php @@ -0,0 +1,19 @@ + true, + 'id' => false + ]; +} diff --git a/src/Model/Table/SocialProfilesTable.php b/src/Model/Table/SocialProfilesTable.php new file mode 100644 index 0000000..406fe01 --- /dev/null +++ b/src/Model/Table/SocialProfilesTable.php @@ -0,0 +1,29 @@ +addBehavior('Timestamp'); + + $this->belongsTo('Users'); + } +} diff --git a/src/Template/Element/login.ctp b/src/Template/Element/login.ctp deleted file mode 100644 index 45d487e..0000000 --- a/src/Template/Element/login.ctp +++ /dev/null @@ -1,16 +0,0 @@ -Flash->render('auth'); - -echo $this->Form->create(); -echo $this->Form->input( - 'provider', - ['value' => 'OpenID'] -); -echo $this->Form->input( - 'openid_identifier', - ['value' => 'https://www.google.com/accounts/o8/id'] -); - -echo $this->Form->submit('Login'); -echo $this->Form->end(); -?> \ No newline at end of file