-
Notifications
You must be signed in to change notification settings - Fork 9
/
Module.php
executable file
·159 lines (138 loc) · 4.86 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<?php
namespace vova07\users;
use Yii;
/**
* Module [[Users]]
* Yii2 users module.
*/
class Module extends \yii\base\Module
{
/**
* @inheritdoc
*/
public $controllerNamespace = 'vova07\users\controllers\frontend';
/**
* @var boolean If true after registration user will be required to confirm his e-mail address.
*/
public $requireEmailConfirmation = true;
/**
* @var string E-mail address from that will be sent the module messages
*/
public $robotEmail;
/**
* @var string Name of e-mail sender.
* By default is `Yii::$app->name . ' robot'`.
*/
public $robotName;
/**
* @var integer The time before a sent activation token becomes invalid.
* By default is 24 hours.
*/
public $activationWithin = 86400; // 24 hours
/**
* @var integer The time before a sent recovery token becomes invalid.
* By default is 4 hours.
*/
public $recoveryWithin = 14400; // 4 hours
/**
* @var integer The time before a sent confirmation token becomes invalid.
* By default is 4 hours.
*/
public $emailWithin = 14400; // 4 hours
/**
* @var integer Users per page
*/
public $recordsPerPage = 10;
/**
* @var array User roles that can access backend module.
*/
public $adminRoles = ['superadmin', 'admin'];
/**
* @var string Temporary path where will be saved user's avatar
*/
public $avatarsTempPath = '@statics/temp/users/avatars';
/**
* @var string Path where will be saved user's avatar
*/
public $avatarPath = '@statics/web/users/avatars';
/**
* @var string Avatars path URL
*/
public $avatarUrl = '/statics/users/avatars';
/**
* @var boolean Is module used for backend.
*/
private $_isBackend;
/**
* @var \yii\swiftmailer\Mailer Mailer instance
*/
private $_mail;
/**
* @inheritdoc
*/
public function init()
{
parent::init();
if ($this->isBackend === true) {
$this->setViewPath('@vova07/users/views/backend');
} else {
$this->setViewPath('@vova07/users/views/frontend');
}
}
/**
* Check if module is used for backend application.
* @return boolean true if it's used for backend application.
*/
public function getIsBackend()
{
if ($this->_isBackend === null) {
$this->_isBackend = strpos($this->controllerNamespace, 'backend') === false ? false : true;
}
return $this->_isBackend;
}
/**
* @return \yii\swiftmailer\Mailer Mailer instance with predefined templates.
*/
public function getMail()
{
if ($this->_mail === null) {
$this->_mail = Yii::$app->getMailer();
$this->_mail->htmlLayout = '@vova07/users/mails/layouts/html';
$this->_mail->textLayout = '@vova07/users/mails/layouts/text';
$this->_mail->viewPath = '@vova07/users/mails/views';
if ($this->robotEmail !== null) {
$this->_mail->messageConfig['from'] = $this->robotName === null ? $this->robotEmail : [$this->robotEmail => $this->robotName];
}
}
return $this->_mail;
}
/**
* Translates a message to the specified language.
*
* This is a shortcut method of [[\yii\i18n\I18N::translate()]].
*
* The translation will be conducted according to the message category and the target language will be used.
*
* You can add parameters to a translation message that will be substituted with the corresponding value after
* translation. The format for this is to use curly brackets around the parameter name as you can see in the following example:
*
* ```php
* $username = 'Alexander';
* echo \Yii::t('app', 'Hello, {username}!', ['username' => $username]);
* ```
*
* Further formatting of message parameters is supported using the [PHP intl extensions](http://www.php.net/manual/en/intro.intl.php)
* message formatter. See [[\yii\i18n\I18N::translate()]] for more details.
*
* @param string $category the message category.
* @param string $message the message to be translated.
* @param array $params the parameters that will be used to replace the corresponding placeholders in the message.
* @param string $language the language code (e.g. `en-US`, `en`). If this is null, the current
* [[\yii\base\Application::language|application language]] will be used.
* @return string the translated message.
*/
public static function t($category, $message, $params = [], $language = null)
{
return Yii::t('vova07/' . $category, $message, $params, $language);
}
}