PHP code example of iiifx-production / yii2-secure-remember-me

1. Go to this page and download the library: Download iiifx-production/yii2-secure-remember-me 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/ */

    

iiifx-production / yii2-secure-remember-me example snippets

 php
    'bootstrap' => [

        /* ... */

        'rememberMe', # Добавляем к загрузочным компонентам приложения
    ],
    
    'components' => [
        'rememberMe' => [ # Добавляем компонент в приложение
            'class' => 'iiifx\yii2\SecureRememberMe\components\Manager',
            # Конфигурация компонента
            'cookieKey' => 'remember-me', # Имя Cookie параметра
            'lifetime' => 2592000, # Время жизни токена, в секундах
            'userClass' => 'common\models\User', # Класс пользователя, который используется в приложении
        ],
        
        /* ... */
        
    ],
 php
    /**
     * Logs in a user using the provided username and password.
     *
     * @return boolean whether the user is logged in successfully
     */
    public function login ()
    {
        if ( $this->validate() ) {
            if ( Yii::$app->user->login( $this->getUser() ) ) {

                # Если разрешен RememberMe пользователем
                if ( $this->rememberMe ) {
                    /** @var \iiifx\yii2\SecureRememberMe\components\Manager $rememberMe */
                    $rememberMe = Yii::$app->rememberMe;
                    # Создаем токен для пользователя
                    $rememberMe->create( $this->_user->id );
                }
                return TRUE;
                
            }
        }
        return FALSE;
    }
 php
    /**
     * Logs out the current user.
     *
     * @return mixed
     */
    public function actionLogout()
    {
        Yii::$app->user->logout();

        /** @var \iiifx\yii2\SecureRememberMe\components\Manager $rememberMe */
        $rememberMe = Yii::$app->rememberMe;
        $rememberMe->delete();

        return $this->goHome();
    }