forked from dektrium/yii2-user
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBootstrap.php
74 lines (66 loc) · 2.34 KB
/
Bootstrap.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
/*
* This file is part of the Dektrium project.
*
* (c) Dektrium project <http://github.com/dektrium/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace dektrium\user;
use yii\base\BootstrapInterface;
use yii\web\GroupUrlRule;
/**
* Bootstrap class registers module and user application component. It also creates some url rules which will be applied
* when UrlManager.enablePrettyUrl is enabled.
*
* @author Dmitry Erofeev <dmeroff@gmail.com>
*/
class Bootstrap implements BootstrapInterface
{
/**
* @inheritdoc
*/
public function bootstrap($app)
{
if ($app->hasModule('user')) {
$identityClass = $app->getModule('user')->manager->userClass;
} else {
$app->setModule('user', [
'class' => 'dektrium\user\Module'
]);
$identityClass = 'dektrium\user\models\User';
}
if ($app instanceof \yii\console\Application) {
$app->getModule('user')->controllerNamespace = 'dektrium\user\commands';
} else {
$app->set('user', [
'class' => 'yii\web\User',
'enableAutoLogin' => true,
'loginUrl' => ['/user/security/login'],
'identityClass' => $identityClass
]);
$app->get('urlManager')->rules[] = new GroupUrlRule([
'prefix' => 'user',
'rules' => [
'<id:\d+>' => 'profile/show',
'<action:(login|logout)>' => 'security/<action>',
'<action:(register|resend)>' => 'registration/<action>',
'confirm/<id:\d+>/<token:\w+>' => 'registration/confirm',
'forgot' => 'recovery/request',
'recover/<id:\d+>/<token:\w+>' => 'recovery/reset',
'settings/<action:\w+>' => 'settings/<action>'
]
]);
if (!$app->has('authClientCollection')) {
$app->set('authClientCollection', [
'class' => 'yii\authclient\Collection',
]);
}
}
$app->get('i18n')->translations['user*'] = [
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => __DIR__ . '/messages',
];
}
}