Бандл - оболочка для hwi/oauth-bundle и friendsofsymfony/user-bundle
Создает кнопки входа и коннекта/дисконекта аккаунта соц. сетей Записывает данные из соц. сетей в бд (Имя, Фамилия, Телефон, ...)
Пока доступны: Vkontakte Facebook Odnoklassniki Mailru Google
-
Установить и настроить
friendsofsymfony/user-bundle -
Установить и настроить
hwi/oauth-bundle
Open a command console, enter your project directory and execute:
$ composer require <package-name>Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:
$ composer require <package-name>This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.
Then, enable the bundle by adding it to the list of registered bundles
in the app/AppKernel.php file of your project:
<?php
// app/AppKernel.php
// ...
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
// ...
new <vendor>\<bundle-name>\<bundle-long-name>(),
);
// ...
}
// ...
}В config/services.yaml сделать сервис публичным:
services:
# ...
Kolyya\OAuthBundle\Security\Core\User\OAuthUserProvider
public: trueи установить его в config/packages/security.yaml
security:
# ...
firewalls:
# ...
main:
# ...
oauth:
# ...
oauth_user_provider:
service: Kolyya\OAuthBundle\Security\Core\User\OAuthUserProvider
# ...и в конфиг для hwi_oauth:
hwi_oauth:
# ...
connect:
account_connector: Kolyya\OAuthBundle\Security\Core\User\OAuthUserProvider
# ...Унаследовать User от Kolyya\OAuthBundle\Entity\OAuthUser:
// src/Entity/User.php
// ...
use Kolyya\OAuthBundle\Entity\OAuthUser;
// ...
class User extends OAuthUser
{
// ...Добавить свойства для хранения данных из соц сетей:
// src/Entity/User.php
// ...
class User extends OAuthUser
{
// ...
/**
* @ORM\Column(type="json_array", nullable=true)
*/
protected $vkontakteData;
/**
* @ORM\Column(type="string", length=128, nullable=true)
*/
protected $vkontakteId;
/**
* @return mixed
*/
public function getVkontakteData()
{
return $this->vkontakteData;
}
/**
* @param mixed $vkontakteData
*/
public function setVkontakteData($vkontakteData)
{
$this->vkontakteData = $vkontakteData;
}
/**
* @return mixed
*/
public function getVkontakteId()
{
return $this->vkontakteId;
}
/**
* @param mixed $vkontakteId
*/
public function setVkontakteId($vkontakteId)
{
$this->vkontakteId = $vkontakteId;
}
// ...
}{# templates/bundles/FOSUserBundle/Security/login.html.twig #}
{# ... #}
{{ kolyya_oauth_buttons() }}
{# ... #}
{# templates/bundles/FOSUserBundle/Profile/show_content.html.twig #}
{# ... #}
{{ kolyya_connect_buttons() }}
{# ... #}
# config/routes.yaml
# ...
kolyya_oauth:
resource: "@KolyyaOAuthBundle/Resources/config/routing.yml"
prefix: /И удалить hwi_oauth_ маршруты
order - порядок и список доступных соц. сетей
order: ['vkontakte', 'facebook', 'odnoklassniki','mailru','google']assets.soc_auth_stylesheet - файл стилей кнопок входа