rmrevin/yii2-ulogin

Extension for yii2 ulogin integration

Installs: 10 905

Dependents: 0

Suggesters: 0

Security: 0

Stars: 15

Watchers: 2

Forks: 9

Open Issues: 2

Type:yii2-extension

1.4.0 2018-06-20 09:21 UTC

This package is not auto-updated.

Last update: 2024-03-16 11:30:58 UTC


README

Installation

The preferred way to install this extension is through composer.

Either run

composer require "rmrevin/yii2-ulogin:~1.4"

or add

"rmrevin/yii2-ulogin": "~1.4",

to the require section of your composer.json file.

Usage

use rmrevin\yii\ulogin\ULogin;

echo ULogin::widget([
    // widget look'n'feel
    'display' => ULogin::D_PANEL,

    // required fields
    'fields' => [ULogin::F_FIRST_NAME, ULogin::F_LAST_NAME, ULogin::F_EMAIL, ULogin::F_PHONE, ULogin::F_CITY, ULogin::F_COUNTRY, ULogin::F_PHOTO_BIG],

    // optional fields
    'optional' => [ULogin::F_BDATE],

    // login providers
    'providers' => [ULogin::P_VKONTAKTE, ULogin::P_FACEBOOK, ULogin::P_TWITTER, ULogin::P_GOOGLE],

    // login providers that are shown when user clicks on additonal providers button
    'hidden' => [],

    // where to should ULogin redirect users after successful login
    'redirectUri' => ['sign/ulogin'],

    // force use https in redirect uri
    'forceRedirectUrlScheme' => 'https',

    // optional params (can be ommited)
    // force widget language (autodetect by default)
    'language' => ULogin::L_RU,

    // providers sorting ('relevant' by default)
    'sortProviders' => ULogin::S_RELEVANT,

    // verify users' email (disabled by default)
    'verifyEmail' => '0',

    // mobile buttons style (enabled by default)
    'mobileButtons' => '1',
]);

Getting user info after success auth (response from ulogin):

use rmrevin\yii\ulogin\AuthAction;

class SiteController extends Controller
{

    public function action()
    {
        return [
            // ...
            'ulogin-auth' => [
                'class' => AuthAction::className(),
                'successCallback' => [$this, 'uloginSuccessCallback'],
                'errorCallback' => function($data){
                    \Yii::error($data['error']);
                },
            ]
        ];
    }

    public function uloginSuccessCallback($attributes)
    {
        print_r($attributes);
    }
}