amnah / yii2-user

Yii2 user authentication module
MIT License
253 stars 104 forks source link

bootstrap without urlmanager enabled #94

Open rtwent opened 9 years ago

rtwent commented 9 years ago

My case is advanced application, amnah user from 5/7/2015. I add components and modules to common configuration. In the frontend part where urlmanager is enabled - everything works perfect. In the backend, I do not need urlmanager, so it is not initialized. The config is: return [

'id' => 'Managing',
'basePath' => dirname(__DIR__),
'bootstrap' => [
    'log',
    function () { return Yii::$app->getModule("user"); }, // to set up /user routes
],
            'controllerNamespace' => 'backend\controllers',
'modules' => [
    'user' => [
        'requireEmail' => false,
        'requireUsername' => true,
        'emailConfirmation' => false,
        'emailChangeConfirmation' => true,
        'loginDuration' => 100,
        'loginEmail' => false,
        'loginUsername' => true,
    ],
],
'components' => [
    'log' => [
        'traceLevel' => YII_DEBUG ? 3 : 0,
        'targets' => [
            [
                'class' => 'yii\log\FileTarget',
                'levels' => ['error', 'warning'],
            ],
        ],
    ],
    'errorHandler' => [
        'errorAction' => 'site/error',
    ],
    'view' => [
        'theme' => [
            'pathMap' => [
                '@app/views' => '@app/themes/adminlte',
                '@vendor/amnah/yii2-user/views' => '@app/themes/adminlte/useranmah',
            ],
            'baseUrl' => '@web/themes/adminlte',
        ],
    ],
    'i18n' => [
        'translations' => [
            'lang*' => [
                'class' => 'yii\i18n\PhpMessageSource',
            ],
            'user' => [
                'class' => 'yii\i18n\PhpMessageSource',
                'basePath' => '@app/messages', // example: @app/messages/fr/user.php
            ]
        ],
    ],
],
'params' => $params,

]; In this configuration /index.php?r=user/login will route to site/error. But with config below (urlManager with prettyUrl enabled) - everything will be fine: return [

'id' => 'Managing',
'basePath' => dirname(__DIR__),
'controllerNamespace' => 'backend\controllers',
'bootstrap' => [
    'log',
    function () { return Yii::$app->getModule("user"); }, // to set up /user routes
],
'modules' => [
    'user' => [
        'requireEmail' => false,
        'requireUsername' => true,
        'emailConfirmation' => false,
        'emailChangeConfirmation' => true,
        'loginDuration' => 100,
        'loginEmail' => false,
        'loginUsername' => true,
    ],
],
'components' => [
    'urlManager' => [
        'enablePrettyUrl' => true,
        'showScriptName' => false,
        'suffix' => '/',
        'rules' => [
            '<controller:\w+>/<id:\d+>' => '<controller>/view',
            '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
            '<controller:\w+>/<action:\w+>' => '<controller>/<action>',
            '<controller:\w+>/' => '<controller>/index',
        ],
    ],
    'log' => [
        'traceLevel' => YII_DEBUG ? 3 : 0,
        'targets' => [
            [
                'class' => 'yii\log\FileTarget',
                'levels' => ['error', 'warning'],
            ],
        ],
    ],
    'errorHandler' => [
        'errorAction' => 'site/error',
    ],
    'view' => [
        'theme' => [
            'pathMap' => [
                '@app/views' => '@app/themes/adminlte',
                '@vendor/amnah/yii2-user/views' => '@app/themes/adminlte/useranmah',
            ],
            'baseUrl' => '@web/themes/adminlte',
        ],
    ],
    'i18n' => [
        'translations' => [
            'lang*' => [
                'class' => 'yii\i18n\PhpMessageSource',
            ],
            'user' => [
                'class' => 'yii\i18n\PhpMessageSource',
                'basePath' => '@app/messages', // example: @app/messages/fr/user.php
            ]
        ],
    ],
],
'params' => $params,

];

Here https://github.com/amnah/yii2-user/blob/master/Module.php#L142 You call to addRules but in documentation http://www.yiiframework.com/doc-2.0/yii-web-urlmanager.html#addRules%28%29-detail is written "Note that if $enablePrettyUrl is false, this method will do nothing."

Thank You for Your work.

amnah commented 9 years ago

Sigh ... I can't think of a good solution. For now I've reverted back to the createController method (and removed the bootstrap)

https://github.com/amnah/yii2-user/commit/824d282ac32b0e0fa32545f6dda9081b4d38b560