Skip to content

Commit e4a8a30

Browse files
committed
Improve error message if twofactorauth has not been installed
1 parent 51bf070 commit e4a8a30

1 file changed

Lines changed: 19 additions & 8 deletions

File tree

src/Controller/Component/OneTimePasswordAuthenticatorComponent.php

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,25 @@ public function initialize(array $config): void
4040
parent::initialize($config);
4141

4242
if (Configure::read('OneTimePasswordAuthenticator.login')) {
43-
$this->tfa = new TwoFactorAuth(
44-
qrcodeprovider: Configure::read('OneTimePasswordAuthenticator.qrcodeprovider'),
45-
issuer: Configure::read('OneTimePasswordAuthenticator.issuer'),
46-
digits: Configure::read('OneTimePasswordAuthenticator.digits'),
47-
period: Configure::read('OneTimePasswordAuthenticator.period'),
48-
algorithm: Configure::read('OneTimePasswordAuthenticator.algorithm'),
49-
rngprovider: Configure::read('OneTimePasswordAuthenticator.rngprovider')
50-
);
43+
try {
44+
$this->tfa = new TwoFactorAuth(
45+
qrcodeprovider: Configure::read('OneTimePasswordAuthenticator.qrcodeprovider'),
46+
issuer: Configure::read('OneTimePasswordAuthenticator.issuer'),
47+
digits: Configure::read('OneTimePasswordAuthenticator.digits'),
48+
period: Configure::read('OneTimePasswordAuthenticator.period'),
49+
algorithm: Configure::read('OneTimePasswordAuthenticator.algorithm'),
50+
rngprovider: Configure::read('OneTimePasswordAuthenticator.rngprovider')
51+
);
52+
} catch (\Throwable $t) {
53+
throw new \RuntimeException(
54+
__d(
55+
'cake_d_c/users',
56+
'An error has occurred configuring OneTimePasswordAuthenticator. ' .
57+
'Please ensure you have installed robthree/twofactorauth and endroid/qr-code ' .
58+
'(or your preferred QR provider).'
59+
)
60+
);
61+
}
5162
}
5263
}
5364

0 commit comments

Comments
 (0)