PHP code example of sergmoro1 / yii2-user

1. Go to this page and download the library: Download sergmoro1/yii2-user 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/ */

    

sergmoro1 / yii2-user example snippets


return [
    ...
    'modules' => [
        'lookup' => ['class' => 'sergmoro1\lookup\Module'],
        'user'   => ['class' => 'sergmoro1\user\Module'],
    ],
    'components' => [
        'authClientCollection' => [
            'class' => 'yii\authclient\Collection',
            'clients' => [
                'yandex' => [
                    'class' => 'yii\authclient\clients\Yandex',
                    'clientId' => 'YandexClientId',
                    'clientSecret' => 'YandexClientSecret',
                ],
            ],
        ],
        'mailer' => [
            'class' => 'yii\swiftmailer\Mailer',
            'useFileTransport' => false,
            'viewPath' => '@vendor/sergmoro1/yii2-user/src/mail',
            /* Example of definition (Yandex)
            'transport' => [
                'class' => 'Swift_SmtpTransport',
                'host' => 'smtp.yandex.ru',
                'username' => '[email protected]',
                'password' => 'your-password',
                'port' => '465',
                'encryption' => 'ssl',
            ],
            */
        ],
    ],

    public function getAvatarImage()
    {
        return $this->getImage('thumb');
    }

namespace frontend\controllers;

use Yii;
use sergmoro1\user\traits\AuthTrait;

class SiteController extends Controller
{
    use AuthTrait;

    /**
     * Handler for EVENT_AFTER_LOGGED_IN. May be defined if needed.
     */
    public function init()
    {
        parent::init();
        $this->on(\sergmoro1\user\Module::EVENT_AFTER_LOGGED_IN, function($event) { Yii::$app->session->setFlash('success', 
            Yii::t('app', 'You are logged in as a commentator. You can leave a comment now.'));
        });
    }
    
    /**
     * inheritdoc
     */
    public function actions()
    {
        return [
            'auth' => [
                'class' => 'yii\authclient\AuthAction',
                'successCallback' => [$this, 'onAuthSuccess'],
            ],
        ];
    }

<?= sergmoro1\user\widgets\SocialCredentials::widget()