File tree Expand file tree Collapse file tree 2 files changed +19
-6
lines changed Expand file tree Collapse file tree 2 files changed +19
-6
lines changed Original file line number Diff line number Diff line change 15
15
class OtpWindow extends Value implements ProcessorInterface
16
16
{
17
17
/**
18
+ * Fetch Totp default period value
19
+ *
18
20
* @return int
19
21
*/
20
22
private function getDefaultPeriod (): int
@@ -48,7 +50,13 @@ public function beforeSave()
48
50
$ value = $ this ->getValue ();
49
51
$ period = $ this ->getDefaultPeriod ();
50
52
if (!is_numeric ($ value ) || $ value < 1 || $ value >= $ period ) {
51
- throw new ValidatorException (__ ('Invalid OTP window value. It must be less than the OTP period value ' .$ period ));
53
+ throw new ValidatorException (
54
+ __ (
55
+ 'Invalid OTP window value. It must be between 1 and %1 as default period is %2 ' ,
56
+ $ period -1 ,
57
+ $ period
58
+ )
59
+ );
52
60
}
53
61
54
62
return parent ::beforeSave ();
Original file line number Diff line number Diff line change @@ -18,11 +18,19 @@ class UpdateOtpWindow implements DataPatchInterface
18
18
*/
19
19
private $ moduleDataSetup ;
20
20
21
+ /**
22
+ * @param ModuleDataSetupInterface $moduleDataSetup
23
+ */
21
24
public function __construct (ModuleDataSetupInterface $ moduleDataSetup )
22
25
{
23
26
$ this ->moduleDataSetup = $ moduleDataSetup ;
24
27
}
25
28
29
+ /**
30
+ * Fetch Totp default period
31
+ *
32
+ * @return int
33
+ */
26
34
public function getDefaultPeriod ()
27
35
{
28
36
return TOTPInterface::DEFAULT_PERIOD ;
@@ -43,17 +51,15 @@ public function apply()
43
51
$ period = $ this ->getDefaultPeriod ();
44
52
if ($ existingValue && $ existingValue >= $ period ) {
45
53
$ newWindowValue = $ period - 1 ;
46
- }
47
-
48
- if ($ existingValue ) {
49
54
$ setup ->update (
50
55
'core_config_data ' ,
51
56
['value ' => $ newWindowValue ],
52
57
'path = "twofactorauth/google/otp_window" '
53
58
);
54
59
}
55
-
56
60
$ setup ->endSetup ();
61
+
62
+ return $ this ;
57
63
}
58
64
59
65
/**
@@ -71,5 +77,4 @@ public function getAliases()
71
77
{
72
78
return [];
73
79
}
74
-
75
80
}
You can’t perform that action at this time.
0 commit comments