forked from dektrium/yii2-user
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Module.php
145 lines (120 loc) · 3.18 KB
/
Module.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<?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\Module as BaseModule;
use yii\console\Application as ConsoleApplication;
/**
* This is the main module class for the Dektrium user module.
*
* @property Factory $factory
*
* @author Dmitry Erofeev <[email protected]>
*/
class Module extends BaseModule
{
const VERSION = '0.5.0';
/**
* @var array Actions on which captcha will be shown.
*/
public $captcha = [];
/**
* @var string Allowed types: 'email', 'username', 'both'
*/
public $loginType = 'email';
/**
* @var bool Whether to allow login without confirmation.
*/
public $allowUnconfirmedLogin = false;
/**
* @var int The time you want the user will be remembered without asking for credentials.
* By default rememberFor is two weeks.
*/
public $rememberFor = 1209600;
/**
* @var bool Whether to generate user password automatically.
*/
public $generatePassword = false;
/**
* @var bool Whether to track user's registration and sign in
*/
public $trackable = true;
/**
* @var bool Whether confirmation needed
*/
public $confirmable = true;
/**
* @var int The time before a sent confirmation token becomes invalid.
* By default confirmWithin is 24 hours.
*/
public $confirmWithin = 86400;
/**
* @var bool Whether to enable password recovery.
*/
public $recoverable = true;
/**
* @var int The time before a recovery token becomes invalid.
* By default recoverWithin is 6 hours.
*/
public $recoverWithin = 21600;
/**
* @var int Cost parameter used by the Blowfish hash algorithm.
*/
public $cost = 10;
/**
* @var string
*/
public $emailViewPath = '@dektrium/user/views/mail';
/**
* @var string|null Role that will be assigned to user on creation.
*/
public $defaultRole = null;
/**
* @var array An array of administrator's usernames.
*/
public $admins = [];
/**
* @var Factory
*/
private $_factory = ['class' => '\dektrium\user\Factory'];
/**
* @inheritdoc
*/
public function init()
{
parent::init();
if (\Yii::$app instanceof ConsoleApplication) {
$this->controllerNamespace = 'dektrium\user\commands';
}
\Yii::$app->getI18n()->translations['user*'] = [
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => __DIR__ . '/messages',
];
}
/**
* @return Factory
*/
public function getFactory()
{
if (is_array($this->_factory)) {
$this->_factory = \Yii::createObject($this->_factory);
}
return $this->_factory;
}
/**
* @param $config
*/
public function setFactory(array $config)
{
if (!isset($config['class'])) {
$config['class'] = '\dektrium\user\Factory';
}
$this->_factory = $config;
}
}