vendor/2amigos/yii2-usuario/src/User/Bootstrap.php
/**
     * Initialize container with module classes.
     *
     * @param \yii\base\Application $app
     * @param array                 $map the previously built class map list
     */
Initialize container with module classes.
@param \yii\base\Application $app
@param array                 $map the previously built class map list
Initialize container with module classes . @param \ yii \ base \ Application $app @param array $map the previously built class map list
protected function initContainer($app, $map)
    {
        $di = Yii::$container;
        try {
            $di->set(Event\FormEvent::class);
            $di->set(Event\ProfileEvent::class);
            $di->set(Event\ResetPasswordEvent::class);
            $di->set(Event\SocialNetworkAuthEvent::class);
            $di->set(Event\SocialNetworkConnectEvent::class);
            $di->set(Event\UserEvent::class);
            $di->set(Form\LoginForm::class);
            $di->set(Form\RecoveryForm::class);
            $di->set(Form\RegistrationForm::class);
            $di->set(Form\ResendForm::class);
            $di->set(Form\SettingsForm::class);
            $di->set(Helper\AuthHelper::class);
            $di->set(Helper\GravatarHelper::class);
            $di->set(Helper\SecurityHelper::class);
            $di->set(Helper\TimezoneHelper::class);
            $di->set(Service\AccountConfirmationService::class);
            $di->set(Service\EmailChangeService::class);
            $di->set(Service\PasswordExpireService::class);
            $di->set(Service\PasswordRecoveryService::class);
            $di->set(Service\ResendConfirmationService::class);
            $di->set(Service\ResetPasswordService::class);
            $di->set(Service\SocialNetworkAccountConnectService::class);
            $di->set(Service\SocialNetworkAuthenticateService::class);
            $di->set(Service\UserBlockService::class);
            $di->set(Service\UserCreateService::class);
            $di->set(Service\UserRegisterService::class);
            $di->set(Service\UserConfirmationService::class);
            $di->set(Service\AuthItemEditionService::class);
            $di->set(Service\UpdateAuthAssignmentsService::class);
            $di->set(Service\SwitchIdentityService::class);
            $di->set(Service\TwoFactorQrCodeUriGeneratorService::class);
            $di->set(Strategy\DefaultEmailChangeStrategy::class);
            $di->set(Strategy\InsecureEmailChangeStrategy::class);
            $di->set(Strategy\SecureEmailChangeStrategy::class);
            $di->set(Validator\AjaxRequestModelValidator::class);
            $di->set(Validator\TimeZoneValidator::class);
            $di->set(Validator\TwoFactorCodeValidator::class);
            $modelClassMap = [];
            foreach ($map as $class => $definition) {
                $di->set($class, $definition);
                $model = is_array($definition) ? $definition['class'] : $definition;
                $name = (substr($class, strrpos($class, '\\') + 1));
                $modelClassMap[$class] = $model;
                if (in_array($name, ['User', 'Profile', 'Token', 'SocialNetworkAccount'])) {
                    $di->set(
                        "Da\\User\\Query\\{$name}Query",
                        function () use ($model) {
                            return $model::find();
                        }
                    );
                }
            }
            $di->setSingleton(ClassMapHelper::class, ClassMapHelper::class, [$modelClassMap]);
            if (!$di->has(Search\UserSearch::class)) {
                $di->set(Search\UserSearch::class, [$di->get(Query\UserQuery::class)]);
            }
            if (!$di->has(Search\PermissionSearch::class)) {
                $di->set(Search\PermissionSearch::class);
            }
            if (!$di->has(Search\RoleSearch::class)) {
                $di->set(Search\RoleSearch::class);
            }
            if (!is_null(Yii::$app->getModule('user')->maxPasswordAge)) {
                Event::on(SecurityController::class, FormEvent::EVENT_AFTER_LOGIN, function (FormEvent $event) {
                    $user = $event->form->user;
                    if ($user->password_age >= Yii::$app->getModule('user')->maxPasswordAge) {
                        Yii::$app->session->setFlash('warning', Yii::t('usuario', 'Your password has expired, you must change it now'));
                        Yii::$app->response->redirect(['/user/settings/account'])->send();
                    }
                });
            }
            if ($app instanceof WebApplication) {
                $di->set(
                    'yii\web\User',
                    [
                        'enableAutoLogin' => $app->getModule('user')->enableAutoLogin,
                        'loginUrl' => ['/user/security/login'],
                        'identityClass' => $di->get(ClassMapHelper::class)->get(User::class),
                    ]
                );
            }
        } catch (Exception $e) {
            die($e);
        }
    }
protected function initContainer ( $ app , $ map ) { $ di = Yii :: $ container ; try { $ di -> set ( Event \ FormEvent :: class ) ; $ di -> set ( Event \ ProfileEvent :: class ) ; $ di -> set ( Event \ ResetPasswordEvent :: class ) ; $ di -> set ( Event \ SocialNetworkAuthEvent :: class ) ; $ di -> set ( Event \ SocialNetworkConnectEvent :: class ) ; $ di -> set ( Event \ UserEvent :: class ) ; $ di -> set ( Form \ LoginForm :: class ) ; $ di -> set ( Form \ RecoveryForm :: class ) ; $ di -> set ( Form \ RegistrationForm :: class ) ; $ di -> set ( Form \ ResendForm :: class ) ; $ di -> set ( Form \ SettingsForm :: class ) ; $ di -> set ( Helper \ AuthHelper :: class ) ; $ di -> set ( Helper \ GravatarHelper :: class ) ; $ di -> set ( Helper \ SecurityHelper :: class ) ; $ di -> set ( Helper \ TimezoneHelper :: class ) ; $ di -> set ( Service \ AccountConfirmationService :: class ) ; $ di -> set ( Service \ EmailChangeService :: class ) ; $ di -> set ( Service \ PasswordExpireService :: class ) ; $ di -> set ( Service \ PasswordRecoveryService :: class ) ; $ di -> set ( Service \ ResendConfirmationService :: class ) ; $ di -> set ( Service \ ResetPasswordService :: class ) ; $ di -> set ( Service \ SocialNetworkAccountConnectService :: class ) ; $ di -> set ( Service \ SocialNetworkAuthenticateService :: class ) ; $ di -> set ( Service \ UserBlockService :: class ) ; $ di -> set ( Service \ UserCreateService :: class ) ; $ di -> set ( Service \ UserRegisterService :: class ) ; $ di -> set ( Service \ UserConfirmationService :: class ) ; $ di -> set ( Service \ AuthItemEditionService :: class ) ; $ di -> set ( Service \ UpdateAuthAssignmentsService :: class ) ; $ di -> set ( Service \ SwitchIdentityService :: class ) ; $ di -> set ( Service \ TwoFactorQrCodeUriGeneratorService :: class ) ; $ di -> set ( Strategy \ DefaultEmailChangeStrategy :: class ) ; $ di -> set ( Strategy \ InsecureEmailChangeStrategy :: class ) ; $ di -> set ( Strategy \ SecureEmailChangeStrategy :: class ) ; $ di -> set ( Validator \ AjaxRequestModelValidator :: class ) ; $ di -> set ( Validator \ TimeZoneValidator :: class ) ; $ di -> set ( Validator \ TwoFactorCodeValidator :: class ) ; $ modelClassMap = [ ] ; foreach ( $ map as $ class => $ definition ) { $ di -> set ( $ class , $ definition ) ; $ model = is_array ( $ definition ) ? $ definition [ 'class' ] : $ definition ; $ name = ( substr ( $ class , strrpos ( $ class , '\\' ) + 1 ) ) ; $ modelClassMap [ $ class ] = $ model ; if ( in_array ( $ name , [ 'User' , 'Profile' , 'Token' , 'SocialNetworkAccount' ] ) ) { $ di -> set ( " Da \\ User \\ Query \\ { $ name } Query " , function ( ) use ( $ model ) { return $ model :: find ( ) ; } ) ; } } $ di -> setSingleton ( ClassMapHelper :: class , ClassMapHelper :: class , [ $ modelClassMap ] ) ; if ( ! $ di -> has ( Search \ UserSearch :: class ) ) { $ di -> set ( Search \ UserSearch :: class , [ $ di -> get ( Query \ UserQuery :: class ) ] ) ; } if ( ! $ di -> has ( Search \ PermissionSearch :: class ) ) { $ di -> set ( Search \ PermissionSearch :: class ) ; } if ( ! $ di -> has ( Search \ RoleSearch :: class ) ) { $ di -> set ( Search \ RoleSearch :: class ) ; } if ( ! is_null ( Yii :: $ app -> getModule ( 'user' ) -> maxPasswordAge ) ) { Event :: on ( SecurityController :: class , FormEvent :: EVENT_AFTER_LOGIN , function ( FormEvent $ event ) { $ user = $ event -> form -> user ; if ( $ user -> password_age >= Yii :: $ app -> getModule ( 'user' ) -> maxPasswordAge ) { Yii :: $ app -> session -> setFlash ( 'warning' , Yii :: t ( 'usuario' , 'Your password has expired, you must change it now' ) ) ; Yii :: $ app -> response -> redirect ( [ '/user/settings/account' ] ) -> send ( ) ; } } ) ; } if ( $ app instanceof WebApplication ) { $ di -> set ( 'yii\web\User' , [ 'enableAutoLogin' => $ app -> getModule ( 'user' ) -> enableAutoLogin , 'loginUrl' => [ '/user/security/login' ] , 'identityClass' => $ di -> get ( ClassMapHelper :: class ) -> get ( User :: class ) , ] ) ; } } catch ( Exception $ e ) { die ( $ e ) ; } }
Initialize container with module classes.
Initialize container with module classes .
// events // forms // helpers // services // email change strategy // validators // class map models + query classes // search classes // Attach an event to check if the password has expired // Force password change // override Yii