Test Failed
Push — master ( cf3dbd...f03535 )
by Jean-Christophe
27:09
created

newTwoFACodeMessage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 1
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 0
c 0
b 0
f 0
dl 0
loc 1
ccs 0
cts 1
cp 0
rs 10
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Ubiquity\controllers\auth;
4
5
use Ubiquity\utils\flash\FlashMessage;
6
7
/**
8
 * 
9
 * Ubiquity\controllers\auth$AuthControllerVariablesTrait
10
 * This class is part of Ubiquity
11
 * @author jc
12
 * @version 1.0.0
13
 *
14 1
 */
15 1
trait AuthControllerVariablesTrait {
16
17
	/**
18
	 * Override for modifying the noAccess message
19
	 *
20
	 * @param FlashMessage $fMessage
21
	 */
22
	protected function noAccessMessage(FlashMessage $fMessage) {
23
	}
24
25
	/**
26
	 * Override for modifying attempts message
27
	 * You can use {_timer} and {_attemptsCount} variables in message content
28
	 *
29
	 * @param FlashMessage $fMessage
30
	 * @param int $attempsCount
31
	 */
32 1
	protected function attemptsNumberMessage(FlashMessage $fMessage, $attempsCount) {
33 1
	}
34
35
	/**
36
	 * To override for modifying the bad login message
37
	 *
38
	 * @param FlashMessage $fMessage
39
	 */
40 1
	protected function badLoginMessage(FlashMessage $fMessage) {
41 1
	}
42
43
	/**
44
	 * To override for modifying the logout message
45
	 *
46
	 * @param FlashMessage $fMessage
47
	 */
48
	protected function terminateMessage(FlashMessage $fMessage) {
49
	}
50
51
	/**
52
	 * To override for modifying the disconnect message
53
	 *
54
	 * @param FlashMessage $fMessage
55
	 */
56
	protected function disconnectedMessage(FlashMessage $fMessage) {
57
	}
58
	
59
	/**
60
	 * To override for modifying the account creation message.
61
	 *
62
	 * @param FlashMessage $fMessage
63
	 */
64
	protected function createAccountMessage(FlashMessage $fMessage) {
65
	}
66
	
67
	/**
68
	 * To override for modifying the account creation message information.
69
	 *
70
	 * @param FlashMessage $fMessage
71
	 */
72
	protected function canCreateAccountMessage(FlashMessage $fMessage) {
73
	}
74
	
75
	/**
76
	 * To override for modifying the error for account creation.
77
	 *
78
	 * @param FlashMessage $fMessage
79
	 */
80
	protected function createAccountErrorMessage(FlashMessage $fMessage) {
81
	}
82
	
83
	/**
84
	 * To override for modifying the 2FA panel message.
85
	 * @param FlashMessage $fMessage
86
	 */
87
	protected function twoFAMessage(FlashMessage $fMessage){
88
		
89
	}
90
	/**
91
	 * To override
92
	 * @param FlashMessage $fMessage
93
	 */
94
	protected function newTwoFACodeMessage(FlashMessage $fMessage){
95
		
96
	}
97
	
98
	/**
99
	 * To override for modifying the message displayed if the 2FA code is bad.
100
	 * @param FlashMessage $fMessage
101
	 */
102
	protected function twoFABadCodeMessage(FlashMessage $fMessage){
103
		
104
	}
105
	
106
	/**
107
	 * To override 
108
	 * Displayed when email is valid.
109
	 * @param FlashMessage $fMessage
110
	 */
111
	protected function emailValidationSuccess(FlashMessage $fMessage){
112
		
113
	}
114
	
115
	/**
116
	 * To override
117
	 * Displayed when email is invalid or if an error occurs.
118
	 * @param FlashMessage $fMessage
119
	 */
120 1
	protected function emailValidationError(FlashMessage $fMessage){
121 1
		
122
	}
123
124
	/**
125
	 * To override
126
	 * Displayed when an account recovery operation is initiated.
127
	 * @param FlashMessage $fMessage
128
	 */
129
	protected function recoveryInitMessage(FlashMessage $fMessage){
1 ignored issue
show
Unused Code introduced by
The parameter $fMessage is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

129
	protected function recoveryInitMessage(/** @scrutinizer ignore-unused */ FlashMessage $fMessage){

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
130
131
	}
132
133
	/**
134
	 * To override
135
	 * Displayed when email is sent for a recovery account operation.
136
	 * @param FlashMessage $fMessage
137
	 */
138
	protected function recoveryEmailSendMessage(FlashMessage $fMessage){
1 ignored issue
show
Unused Code introduced by
The parameter $fMessage is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

138
	protected function recoveryEmailSendMessage(/** @scrutinizer ignore-unused */ FlashMessage $fMessage){

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
139 1
140 1
	}
141
142
	/**
143 1
	 * To override
144 1
	 * Displayed when email is not associated with an existing account.
145
	 * @param FlashMessage $fMessage
146
	 */
147
	protected function recoveryEmailErrorMessage(FlashMessage $fMessage){
1 ignored issue
show
Unused Code introduced by
The parameter $fMessage is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

147
	protected function recoveryEmailErrorMessage(/** @scrutinizer ignore-unused */ FlashMessage $fMessage){

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
148
149
	}
150
151 1
	/**
152 1
	 * To override
153
	 * Displayed when a new password is set with recovery account.
154
	 * @param FlashMessage $fMessage
155 1
	 */
156 1
	protected function resetPasswordSuccessMessage(FlashMessage $fMessage){
1 ignored issue
show
Unused Code introduced by
The parameter $fMessage is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

156
	protected function resetPasswordSuccessMessage(/** @scrutinizer ignore-unused */ FlashMessage $fMessage){

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
157
158
	}
159 1
160 1
	/**
161
	 * To override
162
	 * Displayed when an error occurs when a new password is set with recovery account.
163
	 * @param FlashMessage $fMessage
164
	 */
165
	protected function resetPasswordErrorMessage(FlashMessage $fMessage){
1 ignored issue
show
Unused Code introduced by
The parameter $fMessage is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

165
	protected function resetPasswordErrorMessage(/** @scrutinizer ignore-unused */ FlashMessage $fMessage){

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
166
167
	}
168
169
	/**
170
	 * To override
171
	 * Displayed when the account recovery link is valid.
172
	 * @param FlashMessage $fMessage
173 1
	 */
174 1
	protected function emailAccountRecoverySuccess(FlashMessage $fMessage){
1 ignored issue
show
Unused Code introduced by
The parameter $fMessage is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

174
	protected function emailAccountRecoverySuccess(/** @scrutinizer ignore-unused */ FlashMessage $fMessage){

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
175
176
	}
177 1
178 1
	/**
179
	 * To override
180
	 * Displayed when the account recovery link is not valid.
181
	 * @param FlashMessage $fMessage
182
	 */
183
	protected function emailAccountRecoveryError(FlashMessage $fMessage){
1 ignored issue
show
Unused Code introduced by
The parameter $fMessage is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

183
	protected function emailAccountRecoveryError(/** @scrutinizer ignore-unused */ FlashMessage $fMessage){

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
184 1
185 1
	}
186
187
	/**
188
	 * To override
189
	 * Returns the maximum number of allowed login attempts.
190
	 */
191
	protected function attemptsNumber() {
192
		return;
193
	}
194
195
	/**
196
	 * To override
197
	 * Returns the time before trying to connect again
198
	 * Effective only if attemptsNumber return a number.
199
	 *
200
	 * @return number
201
	 */
202 1
	protected function attemptsTimeout() {
203 1
		return 3 * 60;
204
	}
205
206
	/**
207
	 * Override to define if user info is displayed as string.
208
	 * If set to true, use {{ _infoUser| raw }} in views to display user info.
209
	 * Remember to use $this->jquery->renderView instead of $this->loadView for the javascript generation.
210
	 */
211
	public function _displayInfoAsString() {
212
		return false;
213
	}
214
215
	public function _checkConnectionTimeout() {
216
		return;
217
	}
218
219
	public function _getLoginInputName() {
220
		return 'email';
221
	}
222
223
	protected function loginLabel() {
224
		return \ucfirst ( $this->_getLoginInputName () );
225
	}
226
227
	public function _getPasswordInputName() {
228
		return 'password';
229
	}
230
231
	protected function passwordLabel() {
232
		return \ucfirst ( $this->_getPasswordInputName () );
233
	}
234
	
235
	protected function passwordConfLabel() {
236
		return \ucfirst ( $this->_getPasswordInputName () ).' confirmation';
237
	}
238
239
	/**
240
	 * Returns the body selector (jquery selector used for replacing the content of the page).
241
	 * default: main .container
242
	 *
243
	 * @return string
244
	 */
245
	public function _getBodySelector():string {
246
		return 'main .container';
247
	}
248
249
	protected function rememberCaption():string {
250
		return 'Remember me';
251
	}
252
	/**
253
	 * Returns true for account creation.
254
	 * @return boolean
255
	 */
256
	protected function hasAccountCreation():bool{
257
		return false;
258
	}
259
	
260
	/**
261
	 * 
262
	 * @return bool
263
	 */
264
	protected function hasEmailValidation():bool{
265
		return false;
266
	}
267
268
	/**
269
	 * @return bool
270
	 */
271
	protected function hasAccountRecovery():bool{
272
		return false;
273
	}
274
	
275
	/**
276
	 * To override
277
	 * Returns true for a two factor authentification for this account.
278
	 * @param mixed $accountValue
279
	 * @return bool
280
	 */
281
	protected function has2FA($accountValue=null):bool{
282
		return false;
283
	}
284
285
	/**
286
	 * To override
287
	 * Returns the default size for generated tokens.
288
	 * @return int
289
	 */
290
	protected function getTokenSize():int{
291
		return 6;
292
	}
293
294
	/**
295
	 * Generates a new random 2FA code.
296
	 * You have to override this basic implementation.
297
	 * @return string
298
	 * @throws \Exception
299
	 */
300
	protected function generate2FACode():string{
301
		return \bin2hex ( \random_bytes ($this->getTokenSize()));
302
	}
303
304
	/**
305
	 * Returns the code prefix (which should not be entered by the user). 
306
	 * @return string
307
	 */
308
	protected function towFACodePrefix():string{
309
		return 'U-';
310
	}
311
312
	/**
313
	 * Returns the default validity duration of a mail validation link.
314
	 * @return \DateInterval
315
	 */
316
	protected function emailValidationDuration():\DateInterval{
317
		return new \DateInterval('PT24H');
318
	}
319
320
	/**
321
	 * Returns the default validity duration of a generated 2FA code.
322
	 * @return \DateInterval
323
	 */
324
	protected function twoFACodeDuration():\DateInterval{
325
		return new \DateInterval('PT5M');
326
	}
327
328
	/**
329
	 * @return bool
330
	 */
331
	public function hasRecoveryAccount():bool{
332
		return false;
333
	}
334
	/**
335
	 * Returns the default validity duration for an email account recovery.
336
	 * @return \DateInterval
337
	 */
338
	protected function accountRecoveryDuration():\DateInterval{
339
		return new \DateInterval('PT30M');
340
	}
341
	
342
}
343
344