Completed
Pull Request — master (#361)
by
unknown
03:02
created

Module::hasTimeoutSessionHistory()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 6
1
<?php
2
3
/*
4
 * This file is part of the 2amigos/yii2-usuario project.
5
 *
6
 * (c) 2amigOS! <http://2amigos.us/>
7
 *
8
 * For the full copyright and license information, please view
9
 * the LICENSE file that was distributed with this source code.
10
 */
11
12
namespace Da\User;
13
14
use Da\User\Contracts\MailChangeStrategyInterface;
15
use Da\User\Filter\AccessRuleFilter;
16
use Yii;
17
use yii\base\Module as BaseModule;
18
use yii\helpers\Html;
19
20
/**
21
 * This is the main module class of the yii2-usuario extension.
22
 */
23
class Module extends BaseModule
24
{
25
    /**
26
     * @var bool Enable the 'session history' function
27
     * Using with {@see SessionHistoryDecorator}
28
     */
29
    public $enableSessionHistory = false;
30
    /**
31
     * @var int|bool The number of 'session history' records will be stored for user
32
     * if equals false records will not be deleted
33
     */
34
    public $numberSessionHistory = false;
35
    /**
36
     * @var int|bool The time after which the expired 'session history' will be deleted
37
     * if equals false records will not be deleted
38
     */
39
    public $timeoutSessionHistory = false;
40
    /**
41
     * @var bool whether to enable european G.D.P.R. compliance.
42
     *           This will add a few elements to comply with european general data protection regulation.
43
     *           This regulation affects to all companies in Europe a those companies outside that offer their
44
     *           services to the E.U.
45
     *           List of elements that will be added when this is enabled:
46
     *           - Checkbox to request consent on register form
47
     *           - Forgot me button in profile view.
48
     *           - Download my data button in profile
49
     */
50
    public $enableGdprCompliance = false;
51
    /**
52
     * @var null|array|string with the url to privacy policy.
53
     *                        Must be in the same format as yii/helpers/Url::to requires.
54
     */
55
    public $gdprPrivacyPolicyUrl = null;
56
    /**
57
     * @var array with the name of the user identity properties to be included when user request download of his data.
58
     *            Names can include relations like `profile.name`.
59
     *            GPDR says:
60
     *            > The data subject shall have the right to receive the personal data concerning him or her, which he
61
     *            > or she has provided to a controller, in a structured, commonly used and machine-readable format
62
     */
63
    public $gdprExportProperties = [
64
        'email',
65
        'username',
66
        'profile.public_email',
67
        'profile.name',
68
        'profile.gravatar_email',
69
        'profile.location',
70
        'profile.website',
71
        'profile.bio'
72
    ];
73
    /**
74
     * @var string prefix to be used as a replacement when user requests deletion of his data.
75
     */
76
    public $gdprAnonymizePrefix = 'GDPR';
77
    /**
78
     * @var bool if true, all registered users will be prompted to give consent if they have not gave it earlier.
79
     */
80
    public $gdprRequireConsentToAll = false;
81
    /**
82
     * @var null|string use this to customize the message that will appear as hint in the give consent checkbox
83
     */
84
    public $gdprConsentMessage;
85
    /**
86
     * @var array list of url that does not require explicit data processing consent
87
     *            to be accessed, like own profile, account... You can use wildcards like `route/to/*`. Do not prefix
88
     *            "/" required for redirection, they are used to match against action ids.
89
     *
90
     * @see AccessRuleFilter
91
     */
92
    public $gdprConsentExcludedUrls = [
93
        'user/settings/*'
94
    ];
95
    /**
96
     * @var bool whether to enable two factor authentication or not
97
     */
98
    public $enableTwoFactorAuthentication = false;
99
    /**
100
     * @var int cycles of key generation are set on 30 sec. To avoid sync issues, increased validity up to 60 sec.
101
     * @see http://2fa-library.readthedocs.io/en/latest/
102
     */
103
    public $twoFactorAuthenticationCycles = 1;
104
    /**
105
     * @var bool whether to allow auto login or not
106
     */
107
    public $enableAutoLogin = true;
108
    /**
109
     * @var bool whether to allow registration process or not
110
     */
111
    public $enableRegistration = true;
112
    /**
113
     * @var bool whether to force email confirmation to
114
     */
115
    public $enableEmailConfirmation = true;
116
    /**
117
     * @var bool whether to display flash messages or not
118
     */
119
    public $enableFlashMessages = true;
120
    /**
121
     * @var bool whether to be able to, as an admin, impersonate other users
122
     */
123
    public $enableSwitchIdentities = true;
124
    /**
125
     * @var bool whether to generate passwords automatically and remove the password field from the registration form
126
     */
127
    public $generatePasswords = false;
128
    /**
129
     * @var bool whether to allow login accounts with unconfirmed emails
130
     */
131
    public $allowUnconfirmedEmailLogin = false;
132
    /**
133
     * @var bool whether to enable password recovery or not
134
     */
135
    public $allowPasswordRecovery = true;
136
    /**
137
     * @var bool whether to enable password recovery from the admin console
138
     */
139
    public $allowAdminPasswordRecovery = true;
140
    /**
141
     * @var bool whether user can remove his account
142
     */
143
    public $allowAccountDelete = false;
144
    /**
145
     * @var string the class name of the strategy class to handle user's email change
146
     */
147
    public $emailChangeStrategy = MailChangeStrategyInterface::TYPE_DEFAULT;
148
    /**
149
     * @var int the time user will be auto logged in
150
     */
151
    public $rememberLoginLifespan = 1209600;
152
    /**
153
     * @var int the time before the confirmation token becomes invalid. Defaults to 24 hours
154
     */
155
    public $tokenConfirmationLifespan = 86400;
156
    /**
157
     * @var int the time before a recovery token is invalid. Defaults to 6 hours
158
     */
159
    public $tokenRecoveryLifespan = 21600;
160
    /**
161
     * @var array a list of admin usernames
162
     */
163
    public $administrators = [];
164
    /**
165
     * @var string the administrator permission name
166
     */
167
    public $administratorPermissionName;
168
    /**
169
     * @var string the route prefix
170
     */
171
    public $prefix = 'user';
172
    /**
173
     * @var array MailService configuration
174
     */
175
    public $mailParams = [];
176
    /**
177
     * @var int the cost parameter used by the Blowfish hash algorithm.
178
     *          The higher the value of cost, the longer it takes to generate the hash and to verify a password
179
     *          against it. Higher cost therefore slows down a brute-force attack. For best protection against
180
     *          brute-force attacks, set it to the highest value that is tolerable on production servers. The time taken
181
     *          to compute the hash doubles for every increment by one of $cost
182
     */
183
    public $blowfishCost = 10;
184
    /**
185
     * @var string Web controller namespace
186
     */
187
    public $controllerNamespace = 'Da\User\Controller';
188
    /**
189
     * @var string Console controller namespace
190
     */
191
    public $consoleControllerNamespace = 'Da\User\Command';
192
    /**
193
     * @var array the class map. How the container should load specific classes
194
     * @see Bootstrap::buildClassMap() for more details
195
     */
196
    public $classMap = [];
197
    /**
198
     * @var array the url rules (routes)
199
     */
200
    public $routes = [
201
        '<id:\d+>' => 'profile/show',
202
        '<action:(login|logout)>' => 'security/<action>',
203
        '<action:(register|resend)>' => 'registration/<action>',
204
        'confirm/<id:\d+>/<code:[A-Za-z0-9_-]+>' => 'registration/confirm',
205
        'forgot' => 'recovery/request',
206
        'recover/<id:\d+>/<code:[A-Za-z0-9_-]+>' => 'recovery/reset'
207
    ];
208
    /**
209
     * @var string
210
     */
211
    public $viewPath = '@Da/User/resources/views';
212
    /**
213
     * @var string the session key name to impersonate users. Please, modify it for security reasons!
214
     */
215
    public $switchIdentitySessionKey = 'yuik_usuario';
216
    /**
217
     * @var integer If != NULL sets a max password age in days
218
     */
219
    public $maxPasswordAge;
220
    /**
221
     * @var boolean whether to restrict assignment of permissions to users
222
     */
223
    public $restrictUserPermissionAssignment = false;
224
225
    /**
226
     * @return string with the hit to be used with the give consent checkbox
227
     */
228 7
    public function getConsentMessage()
229
    {
230 7
        $defaultConsentMessage = Yii::t(
231 7
            'usuario',
232 7
            'I agree processing of my personal data and the use of cookies to facilitate the operation of this site. For more information read our {privacyPolicy}',
233
            [
234 7
                'privacyPolicy' => Html::a(
235 7
                    Yii::t('usuario', 'privacy policy'),
236 7
                    $this->gdprPrivacyPolicyUrl,
237 7
                    ['target' => '_blank']
238
                ),
239
            ]
240
        );
241
242 7
        return $this->gdprConsentMessage ?: $defaultConsentMessage;
243
    }
244
245
    /**
246
     * @return bool
247
     */
248
    public function hasNumberSessionHistory()
249
    {
250
        return $this->numberSessionHistory !== false && $this->numberSessionHistory > 0;
251
    }
252
253
    /**
254
     * @return bool
255
     */
256
    public function hasTimeoutSessionHistory()
257
    {
258
        return $this->timeoutSessionHistory !== false && $this->timeoutSessionHistory > 0;
259
    }
260
}
261